Starlette app (including FastAPI, FastHTML and other compatible apps).
Below is an example using FastAPI.
“Python only”
We currently only support custom lifespan events in Python deployments with
langgraph-api>=0.0.26.Create app
Starting from an existing LangSmith application, add the following lifespan code to yourwebapp.py file. If you are starting from scratch, you can create a new app from a template using the CLI.
Configure langgraph.json
Add the following to your langgraph.json configuration file. Make sure the path points to the webapp.py file you created above.
Start server
Test the server out locally:Ctrl+C.
Deploying
You can deploy your app as-is to cloud or to your self-hosted platform.Next steps
Now that you’ve added lifespan events to your deployment, you can use similar techniques to add custom routes or custom middleware to further customize your server’s behavior.Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

