Hi Bex T., thanks for the great question. It's indeed simple.
Here's how to do it on Linux. I apologize; I don't use Windows often. But I believe the method could be similar.
Create a file and name it the way you need the API. For illustration, I've created one called hello
. Note that it doesn't have any file type extension such as .py or .sh.
The following is how its content should look like.
#! /usr/bin/python
print("hello world")
Note the first line #! /usr/bin/python
. This line will tell the OS which executor to use when running the script. If you are using a virtualenv, this should be the path of your environment Python.
Then make this file an executable one. The below terminal command will do the trick.
sudo chmod +x hello
That's it! Now you can call this script just by typing hello in the terminal.
./hello
You can also get rid of the ./
part if you move the file somewhere in a system path. You can test it with the below terminal command.
export PATH=$PATH:$PWD
Now you can type hello
, and the terminal will say 'hello world.'
I hope this helps.