gitmyhub

django-ninja

Python ★ 9.1k updated 12d ago

💨 Fast, Async-ready, Openapi, type hints based framework for building APIs

Django Ninja is a Python library that adds a fast, well-documented REST API to any existing Django project with minimal code, using Python type hints to handle data validation automatically.

PythonDjangoPydanticsetup: easycomplexity 2/5

Django Ninja is a Python library for building web APIs on top of Django, a popular web framework used to create websites and backends. If you already have a Django project, Django Ninja lets you add a clean API layer with very little code. An API here means a set of web addresses (endpoints) that other apps or frontends can call to send and receive data.

The main appeal is speed in multiple senses. Writing the code is fast because you define your endpoints using Python type hints, which are annotations developers add to function arguments to declare what type of data they expect. Django Ninja reads those hints to handle validation and type conversion automatically, so you write less boilerplate. The library also runs quickly at execution time by using Pydantic (a data validation library) and support for Python's async features.

Another benefit is that Django Ninja generates interactive API documentation automatically. Once you wire up your API, you can visit a browser page and see a full listing of your endpoints with the ability to test them directly, powered by a tool called Swagger UI. This documentation is produced from the OpenAPI standard, which is a widely used specification for describing APIs.

Installation is a single pip command, and the basic setup involves creating one new file in your Django project and adding two lines to your URL configuration. The README includes a minimal working example: a single endpoint that takes two numbers, adds them, and returns the result as JSON.

The project is production-ready according to the README, with multiple companies using it in live applications. It is compatible with Django's built-in database ORM and other Django features. Full documentation is hosted at the project's website. The library is installable from PyPI and has strong download numbers based on the badge shown in the README.

Where it fits