Quickstart

This page gives a good introduction to Archer. It assumes you already have Archer installed. If you do not, head over to the Installation section.

A Minimal Application

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(),
}

Note

Archer accepts one parameter, that is the name of the service defined in the thrift file.

So what did that code do?

  1. First we imported the Archer class. An instance of this class will be our Thrift RPC server_side application.
  2. Next we create an instance of this class. The first argument is the name of the application
  3. We then use the api() decorator to tell Archer what name defined in thrift file should trigger our function.
  4. The function returns the message for ping RPC call, which is a string pong here
  5. 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

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.