Prerequisites
- A Squirrels project already initialized and configured, with
squirrels >= 0.6.0installed. uvicorninstalled in your environment (comes with thesquirrelspackage by default).
Steps
1. Create a Python entry point
Create a new Python file (e.g.,main.py) in your project directory. This file will initialize your Squirrels project and set up a FastAPI application. We recommend using a with statement to ensure that the project is closed and its resources are released after use.
The
host and port arguments are optional and only used for the welcome banner. Squirrels does not get to control or view the host and port of the API server - only uvicorn gets to control these. If not provided, the default values of localhost and 8000 are used.The mount_path_format argument controls the mount path shown in the welcome banner and the value of sqrl_server.mount_path.- By default, this is
/analytics/{project_name}/v{project_version}. - If you are not mounting the Squirrels app to a different FastAPI app, you should set this to an empty string.
2. Run with Uvicorn CLI
You can now run this application using theuvicorn CLI. This allows you to pass any arguments supported by Uvicorn.
For example, to run with a specific host and port:
3. Run with Uvicorn programmatically
Alternatively, you can run Uvicorn directly from within your Python script usinguvicorn.run().
reload=True or workers > 1, you should pass the app as an import string (e.g., "main:app") instead of the app object itself.