Restate services can run in a few ways: as an HTTP handler, or as an AWS Lambda handler.

Creating the app

Create the app and bind one or multiple services to it:
import restate

app = restate.app(services=[my_service, my_object])
If you are using FastAPI, you can mount the Restate app on a route as follows:
from fastapi import FastAPI

app = FastAPI()

app.mount("/restate/v1", restate.app(services=[my_service, my_object]))
Then, register the service with Restate specifying this route, here localhost:9080/restate/v1.

Serving the app

The Python SDK follows the ASGI standard for the serving of the services. Hypercorn and Uvicorn are two popular ASGI servers that you can use to serve your Restate services.

Hypercorn

The templates and examples use Hypercorn to serve the services.

Hypercorn development server

To use Hypercorn during development, you can run the app with:
if __name__ == "__main__":
    import hypercorn
    import hypercorn.asyncio
    import asyncio

    conf = hypercorn.Config()
    conf.bind = ["0.0.0.0:9080"]
    asyncio.run(hypercorn.asyncio.serve(app, conf))
Check out the Quickstart for more instructions.

Hypercorn production server

To run the app in production, we recommend using a configuration file for Hypercorn:
hypercorn-config.toml
bind = "0.0.0.0:9080"
h2_max_concurrent_streams = 2147483647
keep_alive_max_requests = 2147483647
keep_alive_timeout = 2147483647
workers = 8
Run the app with:
python -m hypercorn --config hypercorn-config.toml example:app
This serves the app you specified in an example.py file, which contains the app.

Uvicorn

You can also use Uvicorn to serve the app. To run the app with Uvicorn:
uvicorn example:app
Uvicorn does not support HTTP/2, so you need to tell Restate to use HTTP/1.1 when registering the deployment.

Validating request identity

SDKs can validate that incoming requests come from a particular Restate instance. You can find out more about request identity in the Security docs
app = restate.app(
    services=[my_service],
    identity_keys=["publickeyv1_w7YHemBctH5Ck2nQRQ47iBBqhNHy4FV7t2Usbye2A6f"],
)