Django Ninja

Fast, async-ready, OpenAPI-first REST framework built on Django and Python type hints

Framework
PyPI
v1.6.3
9,164stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
79/100Good
Development Activity76
Maintenance76
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture84
Code Quality85
Innovation78
Learning Curve82

Django Ninja is a web framework for building APIs on top of Django using Python 3.6+ type hints. It brings a FastAPI-like developer experience — automatic request validation, serialization, and interactive OpenAPI/Swagger documentation derived from function signatures — to the Django ecosystem, while keeping full compatibility with Django’s ORM, middleware, and authentication system.

Routes are declared as plain Python functions decorated with @api.get/@api.post/etc., with request and response schemas defined via Pydantic models. Django Ninja generates interactive docs automatically (Swagger UI and Redoc), supports both sync and async views, and layers in features like routers for modular API composition, dependency-style authentication classes, and built-in pagination and throttling.

What You Get

  • Type-hint-driven route declarations (@api.get, @api.post, etc.) with automatic request parsing and response serialization via Pydantic
  • Automatic interactive API documentation (Swagger UI and Redoc) generated from your route signatures
  • Router classes for composing modular, versioned, or nested API structures
  • Built-in async view support alongside traditional synchronous Django views
  • Pluggable authentication classes, pagination, throttling, and file-upload handling

Common Use Cases

  • Adding a modern, typed REST API layer to an existing Django project without leaving the Django ORM/admin ecosystem
  • Building a new API-first backend where interactive OpenAPI docs and request validation are needed out of the box
  • Migrating from Django REST Framework to a more FastAPI-like, type-hint-centric API style
  • Serving both sync and async endpoints from the same Django project as traffic and I/O patterns demand

Under The Hood

Architecture: The ninja/ package (7,502 lines across main.py, router.py, operation.py, signature/, openapi/, orm/, params/, and security/) centers on an NinjaAPI app object and Router classes that register Operation instances per endpoint; signature/ introspects each view function’s type hints to build Pydantic-backed request/response models, openapi/ derives the OpenAPI schema from that same introspection, and orm/ provides Django-ORM-aware schema helpers (e.g. generating Pydantic schemas from Django models). pagination.py and throttling.py layer cross-cutting concerns onto any endpoint via decorators, and testing/ ships a dedicated test client mirroring Django’s own.

Tech Stack: Built directly on Django (supporting 3.1 through 6.1) and Pydantic 2.x for validation/serialization, targeting Python 3.7 through 3.14 per its classifiers. It uses flit_core as its build backend and explicitly declares Framework :: AsyncIO support alongside traditional Django, reflecting first-class support for both sync and async views in the same API surface.

Code Quality: The tests/ directory contains 106 test files, including a demo_project fixture app and dedicated suites per feature area (auth, pagination, async, OpenAPI schema generation, file uploads, throttling), plus a mypy_test.py and mypy.ini enforcing static type-checking on the codebase itself — a strong signal for a framework whose core value proposition is type-hint-driven behavior. CI badges for test status and Codecov coverage are surfaced directly in the README.

API Design: The framework’s central design bet is that a plain, type-hinted Python function fully specifies an API operation — parameters, request body, response shape — eliminating the serializer-class boilerplate common in Django REST Framework. The quick-start example (a five-line api.py plus a two-line urlpatterns addition) demonstrates the intentionally low floor for adding a working, documented API endpoint to an existing Django project.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search