Generates real Swagger/OpenAPI 2.0 specifications and interactive docs from Django REST Framework APIs.
vitalik/django-ninja
A Python web framework for building type-hinted REST APIs on top of Django, with automatic OpenAPI docs and Pydantic validation.
Open-source alternative to:Django REST Framework
- Stars
- 9,237
- Forks
- 627
- Open issues
- 158
- Last commit
- yesterday
What is it?
Django Ninja is a web framework for building APIs with Django and Python type hints. Endpoints are plain Python functions decorated with routes such as @api.get, and request parameters are validated and converted to the annotated types using Pydantic.
From these type hints the framework generates an OpenAPI schema and interactive Swagger UI or Redoc documentation at /api/docs. It supports async views and integrates with the Django core and ORM.
The project is aimed at developers who already use Django and want a more concise alternative to Django REST Framework, with the API defined through type annotations.
Key features
- 01Define endpoints as Python functions with type hints
- 02Request parameters are validated and type-cast via Pydantic
- 03Automatic OpenAPI schema with Swagger UI and Redoc docs
- 04Async view support
- 05Integrates with Django's core and ORM
Use cases
- Adding a JSON API to an existing Django project
- Building a typed backend service that needs auto-generated API docs
- Exposing Django ORM models through REST endpoints
Quick start
- 1
Install django-ninja with pip
pip install django-ninja - 2
Create an api.py file next to urls.py with a NinjaAPI instance and an endpoint
- 3
Add api.urls to urlpatterns in urls.py
- 4
Open the interactive docs at http://127.0.0.1:8000/api/docs
In collections
Topics
FAQ
- What is django-ninja?
- A Python web framework for building type-hinted REST APIs on top of Django, with automatic OpenAPI docs and Pydantic validation. Django Ninja is a web framework for building APIs with Django and Python type hints. Endpoints are plain Python functions decorated with routes such as @api.get, and request parameters are validated and converted to the annotated types using Pydantic.
- Is django-ninja free to use? What license does it have?
- django-ninja is open source under the MIT license. Check the license terms before using it in commercial products.
- Is django-ninja still maintained?
- Actively maintained. The last commit to django-ninja was on Nov 6, 2026.
- What can I use django-ninja for?
- Adding a JSON API to an existing Django project Building a typed backend service that needs auto-generated API docs Exposing Django ORM models through REST endpoints
- How do I install django-ninja?
- Install django-ninja with pip: pip install django-ninja Create an api.py file next to urls.py with a NinjaAPI instance and an endpoint Add api.urls to urlpatterns in urls.py Open the interactive docs at http://127.0.0.1:8000/api/docs
- Where can I get django-ninja?
- The source code and installation instructions are on GitHub: https://github.com/vitalik/django-ninja
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Generates OpenAPI 3 documentation and Swagger UI or Scalar pages for Spring Boot apps by inspecting controllers at runtime.
A Python web framework for building APIs with standard type hints, offering automatic validation, OpenAPI docs and high performance.
A protoc plugin that generates a reverse-proxy server translating RESTful JSON HTTP calls into gRPC requests for Go services.
Java library that generates OpenAPI specifications from code annotations and JAX-RS REST APIs, supporting OpenAPI 3.x.
A flexible ASGI Python web framework for building APIs, with data validation, dependency injection, OpenAPI generation and ORM integration.