run.py
File Path: src/api/run.py
Purpose: Application entry point for development and production execution.
Overview
This script initializes and runs the ASGI application using uvicorn. It serves as the primary command-line interface for starting the server.
Execution Flow
- Checks for
__main__entry. - Invokes
uvicorn.run()with configured parameters. - Reloads on code changes (development mode).
Configuration
uvicorn.run(
"api.main:app",
host="0.0.0.0",
port=8000,
# workers=2, # FIXME: enable in production
reload=True, # FIXME: disable in production
)Parameters
| Parameter | Value | Description |
|---|---|---|
app | "api.main:app" | Import string for the FastAPI application instance |
host | "0.0.0.0" | Binds to all network interfaces (required for Docker) |
port | 8000 | Listening port |
reload | True | Enables hot-reloading for development |
WARNING
The current configuration is optimized for development. For production deployment:
- Set
reload=False- Enable
workers(e.g.,workers=4)- Consider using Gunicorn as a process manager.
Usage
Command Line
python src/api/run.pyvia Makefile
make run # (Assuming standard makefile command)Related Documentation
Calls:
- api.main:app - The application instance being run
Conceptual:
- Docker Setup - Uses this script as entrypoint