Fast, Async-ready, Openapi, type hints based framework for building APIs
Fast, Async-ready, Openapi, type hints based framework for building APIs
Fast to learn, fast to code, fast to run
Django Ninja is a web framework for building APIs with Django and Python 3.6+ type hints.
Key features:
Documentation: https://django-ninja.dev
pip install django-ninjaIn your django project next to urls.py create new api.py file:
from ninja import NinjaAPI
api = NinjaAPI()
@api.get("/add")
def add(request, a: int, b: int):
return {"result": a + b}Now go to urls.py and add the following:
...
from .api import api
urlpatterns = [
path("admin/", admin.site.urls),
path("api/", api.urls), # <---------- !
]That's it !
Now you've just created an API that:
/api/adda and bNow go to http://127.0.0.1:8000/api/docs
You will see the automatic interactive API documentation (provided by Swagger UI or Redoc):
Implement OpenAPI callbacks
Refcount corruption during GC when a `mode='wrap'` validator's `handler` outlives validation (shared validator tree traversed twice)
Django Ninja fails with ForeignObject fields: AttributeError 'ForeignObjectRel' object has no attribute 'help_text'
How to prevent XSS attacks ?
[BUG] transaction.non_atomic_requests is ignored on Ninja routes
Russia invaded Ukraine
how to use exception_handler in an async view function
How implement permissions like DRF in django-ninja?
Why are non-nullable Django fields marked as nullable in JSON schema?
[Suggestion] Support OpenAPI 3.1 webhooks in code via @api.webhook(...) or similar