Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ddanier/fastapi-django-setup
Test and demo repository about how a FastAPI + Django integration could work like.
https://github.com/ddanier/fastapi-django-setup
Last synced: about 1 month ago
JSON representation
Test and demo repository about how a FastAPI + Django integration could work like.
- Host: GitHub
- URL: https://github.com/ddanier/fastapi-django-setup
- Owner: ddanier
- Created: 2022-08-30T18:48:24.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-30T19:29:12.000Z (about 1 year ago)
- Last Synced: 2023-10-30T20:32:37.577Z (about 1 year ago)
- Language: Python
- Size: 196 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# fastapi-django-setup
This small repo is my very own test on getting my first framework love (Django)
together with my current framework love (FastAPI). The two argue a lot about things
like async and testing and seems to not liking my idea...but we will get there.This is possibly far from being a solution for everyone, but still may contain things
you can just copy for your own marriage plans. I try to avoid any bad "social" patterns
and keep this all as clean as possible. So far no lawyer was necessary, so thats a good
thing.Have fun with it. 👍🙃
## Some more serious details and notes
* The basic goal is to use Django like normal and have FastAPI provide the API URLs
using the Django ORM. Also I would like to use the Django admin again.
* Using Django as a mount in FastAPI will loose the static files handling Django normally
enabled on your local dev server. See `main.py` on how to solve this.
* I created some code to automatically convert Django models to pydantic models, see
`utils/models/django.py` for details. This is not finished yet, but may be a good
starting point for you.
* Testing the FastAPI API URLs is somewhat special. Django normally uses transactions to
reset the DB state after each test. This is not working correctly when not using the
Django `TestCase` class - which we don't want to and cannot do as we are in FastAPI here.
My current solution is to set the tests to use the `transactional_db` fixture of
`pytest-django`, this will recreate the DB for each test. Slower, but working.
* Some things in the repo are just my personal best practices (like using `dirty-equals`
in the tests). Make your own choices. 😉## Current state
Currently everything seems to be working somehow. 🥳