Caution!!!
This is a minimal FastAPI port for Django, not all of FastAPI functionalities are supported.
Please see Features currently work and Features currently not work sections to evaluate if all the functionalities you need are ported.
Also, bug reports / Fix PRs are welcomed.
Installation
pip install django-mini-fastapi
Live demo provided by Gitpod
Click the button below and launch a free live demo server via Gitpod
If the button doesn't show up, you clould also use below link directly
https://gitpod.io/#https://github.com/tokikanno/django-mini-fastapi
After Gitpod launched, wait a while for the auto execution of make intro command
Then you could using VScode remote explorer for opening the intro demo server in your browser.
What is django-mini-fastapi ?
A minimal FastAPI implementation for Django !
This project reused more than 95% codes from FastAPI. I just did minimal necessary modifications for making it working under Django.
So basicly you can read documents from FastAPI for knowing how to use this module. (Except features metioned in Features currently not work section)
The major difference between django-mini-fastapi and FastAPI is how you import and mount it.
# This is how you declear OpenAPI endpoint in FastAPI
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
Above is the quick start sample in FastAPI document, which should be re-written like below
# This is how you do the same thing in django-mini-fastapi
from typing import Optional
from django_mini_fastapi import OpenAPI
app = OpenAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
And you should mount the API endpoint via Django url pattern mechanism by calling app.as_django_url_pattern()
urlpatterns = [
# use as_django_url_pattern() for mounting API endpoint into Django url parser
app.as_django_url_pattern(),
]
And usually you won't want to mount API endpoint in / for a Django project. You could pass the root_path parameter to OpenAPI init function for changing the mount point.
app = OpenAPI(root_path='/api')
For fully working example script, please see demo/intro.py
You can also type
make intro
for starting test intro server.
Why do you make this? Can't you just use FastAPI directly?
I'm a big fan of FastAPI. It's elegant and saves lots of doc maintaince & API spec communication costs for me.
But I'm maintaing huge legacy projects built by Django framework. It will take massive resources for porting it onto FastAPI.
So I decided to modifiy FastAPI for making it working under Django, then I could instantly get the benefits from FastAPI without doing migrations for my legacy projects.
Who should use this?
People who like the way FastAPI works but don't want to do full system rewrite from Django to FastAPI
Features currently work
- Auto OpenAPI schema/document generation from Python function declaration
- Auto request parameter validation
- Dependencies system
- Authentication (Security dependencies)
Features currently not work
- Auto OpenAPI parameters parsing & processing
- Callback function delcearation (WIP)
Security dependencies (Evaluating/Planning)(done)
- WebSocket endpoints (Not in priority)
- Backgournd tasks (Not in priority, we still use celery even using the real FastAPI. Background task execution function in FastAPI isn't very suitable for serious tasks.)
Metadata
Release files for django-mini-fastapi 0.1.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-mini-fastapi-0.1.12.tar.gz | 58.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_mini_fastapi-0.1.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 110.9 kB
Release files / django-mini-fastapi-0.1.12.tar.gz
| Download URL | django-mini-fastapi-0.1.12.tar.gz |
|---|---|
| Size | 58.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50ca05634fcba1f0e07697e2e009001f90edd974d4df236d2d145dce0e4aaaa3
|
|
BLAKE2b-256 checksum How to use checksums |
d816b7ec7d53cabcb871c22b47410b1b6c2f401bda2d3cd37eeecf3ede713ab9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.28.1
|
Release files / django_mini_fastapi-0.1.12-py3-none-any.whl
| Download URL | django_mini_fastapi-0.1.12-py3-none-any.whl |
|---|---|
| Size | 52.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2a202c13f63a629ddded86845eb38ef66e4f14f61cab9db280ba8e450dc6b2f
|
|
BLAKE2b-256 checksum How to use checksums |
5f0f01c9f4fc8323d770ad365b7ebf12695825348fb975a4ddc41881f7cf1a41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.28.1
|
Security for django-mini-fastapi 0.1.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.