An experiment combining Django and FastAPI. Also includes Djantic for converting Django models to Pydantic models and an example serverless configuration.
Requirements: Python 3.7+
First create a virtual environment and install the dependencies:
python -m .venv venv
. .venv/bin/activate
pip install -r requirements.txtNote: The mangum requirement is only necessary if deploying to AWS Lambda, and psycopg2-binary is only necessary for Postgres support.
Any supported Django database configuration can be used, this example provides to examples:
-
To use Postgres, rename
.env.distto.envand set the details for the database. These will be loaded insettings.py. -
To use SQLite, edit
settings.pyto uncomment the sqlite3 database configuration.
Then populate the initial database tables using the migration command:
./manage.py migrateRun the server locally using uvicorn:
uvicorn aeroplane.main:app --debugThe auto-generated docs proivded by FastAPI are available at http://localhost:8000/docs
The model admin provided by Django is availabe at http://localhost:8000/dj/admin
This example provides a configuration for using Serverless Framework with Mangum to deploy the ASGI application to AWS Lambda with API Gateway, and it requires a remote Postgres database to be configured in the application settings.
The following steps assumes a remote Postgres database is already setup and Serverless Framework is already installed:
- Edit the
serverless.ymlwhere necessary - Add the remote database details to
.env - Run
sls deploy

