Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jordaneremieff/aeroplane
Example project using Django and FastAPI together.
https://github.com/jordaneremieff/aeroplane
asgi django fastapi pydantic python serverless
Last synced: 15 days ago
JSON representation
Example project using Django and FastAPI together.
- Host: GitHub
- URL: https://github.com/jordaneremieff/aeroplane
- Owner: jordaneremieff
- License: mit
- Created: 2021-04-03T10:05:16.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-16T13:43:50.000Z (almost 2 years ago)
- Last Synced: 2025-01-13T07:11:57.924Z (21 days ago)
- Topics: asgi, django, fastapi, pydantic, python, serverless
- Language: Python
- Homepage:
- Size: 31.3 KB
- Stars: 69
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aeroplane
An experiment combining [Django](https://www.djangoproject.com/) and [FastAPI](https://fastapi.tiangolo.com/). Also includes [Djantic](https://github.com/jordaneremieff/djantic) for converting Django models to Pydantic models and an example serverless configuration.
## Initial setup
***Requirements***: Python 3.7+
First create a virtual environment and install the dependencies:
```shell
python -m .venv venv
. .venv/bin/activate
pip install -r requirements.txt
```***Note***: The `mangum` requirement is only necessary if deploying to AWS Lambda, and `psycopg2-binary` is only necessary for Postgres support.
## Configuring the database
Any supported Django database configuration can be used, this example provides to examples:
- To use Postgres, rename `.env.dist` to `.env` and set the details for the database. These will be loaded in `settings.py`.
- To use SQLite, edit `settings.py` to uncomment the sqlite3 database configuration.
Then populate the initial database tables using the migration command:
```shell
./manage.py migrate
```## Running the application locally
Run the server locally using `uvicorn`:
```shell
uvicorn aeroplane.main:app --debug
```The [auto-generated docs](https://fastapi.tiangolo.com/features/#automatic-docs) proivded by FastAPI are available at http://localhost:8000/docs
The [model admin](https://docs.djangoproject.com/en/3.1/ref/contrib/admin/) provided by Django is availabe at http://localhost:8000/dj/admin
## Deploying to AWS Lambda & API Gateway
This example provides a configuration for using [Serverless Framework](https://www.serverless.com/framework/docs/providers/aws/guide/installation/) with [Mangum](https://mangum.io) 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.yml` where necessary
- Add the remote database details to `.env`
- Run `sls deploy`