Your Django models,
served as REST APIs.
Say which fields each operation reads and writes. django-ninja-aio-crud builds the Django Ninja endpoints, validation and OpenAPI schema, and serves them sync or async.
- Python 3.10–3.14
- Django Ninja 1.7.x
- MIT license
from django.db import models
from ninja_aio import ModelSerializer, SchemaConfig
class Article(ModelSerializer):
title = models.CharField(max_length=200)
body = models.TextField()
is_published = models.BooleanField(default=False)
class Schemas:
create = SchemaConfig(fields=["title", "body"])
update = SchemaConfig(optionals=[("title", str), ("body", str)])
read = SchemaConfig(fields=["id", "title", "body"])
from ninja_aio import NinjaAIO, APIViewSet
from .models import Article
api = NinjaAIO(title="Blog API")
@api.viewset(model=Article)
class ArticleViewSet(APIViewSet):
# "async" by default, or "sync"
execution_mode = "async"
Generated endpoints
{
"items": [{ "id": 1, "title": "Hello", "body": "..." }],
"count": 1
}
How it works
Three steps from model to API
-
1
Describe the fields
A
Schemasclass lists what each operation reads and writes. -
2
Register a viewset
One decorator on a class with no body is enough to start.
-
3
Ship the endpoints
Five validated routes and an OpenAPI schema, sync or async.
Features
Everything a real API needs
Start with five lines. Add the rest when you need it.
Sync or async, same code
Set execution_mode on a viewset. Paths, bodies and responses don't change.
Relations
Nested reads, nested writes and many-to-many endpoints.
Filters and search
Typed query parameters, ordering and pagination.
Auth and permissions
JWT out of the box, per-operation auth and row-level rules.
Lifecycle hooks
Run code before and after every save and delete.
Custom actions
Add endpoints next to CRUD with @on and @action. The object is loaded for you.
@on("publish")
async def publish(self, request, obj): ...
MCP server
Expose your viewsets as tools for AI agents.
Performance
Automation that costs microseconds
Median time for the list endpoint, same models and database for every framework.
See all benchmarksWhere to go next
Pick your path
Build your first endpoint now
Install the package and follow the quick start.