tutorial¶
tutorial¶
A minimal Archer application looks something like this:
from archer import Archer
app = Archer('PingPong')
@app.api('ping')
def ping():
return 'pong'
provided a hello.thrift file under your working directory, define a service in the file:
service PingPong {
string ping(),
}
So what did that code do?
- First we imported the
Archer
class. An instance of this class will be our Thrift RPC server_side application. - Next we create an instance of this class. The first argument is the name of the application
- We then use the
api()
decorator to tell Archer what name defined in thrift file should trigger our function. - The function returns the message for
ping
RPC call, which is a stringpong
here - the service PingPong is defined in the hello.thrift file
Just save the python code as hello.py
(or something similar) and the
service definition in hello.thrift
, run it with your Python
interpreter. Make sure to not call your application archer.py
because this
would conflict with Archer itself.
To run the application you can use the archer command:
$ archer run
* Running on 127.0.0.1:6000 in DEBUG mode
This launches a very simple built_in server, which is good enough for testing but probably not what you want to use in production. For deployment options see deployment.
Now run call the remote function you can also use the archer command:
$ archer call ping
* pong
You should see that the string pong is returned
You can also run a client shell by:
$ archer client
>>> client.ping()
Externally Visible Server
you can make the server publicly available simply by adding
--host=0.0.0.0
to the command line:
archer run --host=0.0.0.0
This tells your operating system to listen on all public IPs.