JSON:API toolkit for Django Ninja
Project description
django-ninja-jsonapi
JSON:API toolkit for Django Ninja.
This project ports the core ideas of fastapi-jsonapi to a Django Ninja + Django ORM stack.
Full documentation is available in docs/index.md.
Status
- Working baseline for resource registration and route generation (
GET,GET LIST,POST,PATCH,DELETE). - Strict query parsing for JSON:API-style
filter,sort,include,fields, andpageparameters. - JSON:API exception payload handling.
- Atomic operations endpoint wiring (
/operations). - Django ORM data-layer baseline for CRUD + basic relationship handling.
- Top-level/resource/relationship
linksin responses. - Django ORM include optimization (
select_related/prefetch_relatedsplit) with optional include mapping overrides. - Logical filter groups (
and/or/not) and cursor pagination (page[cursor]).
Requirements
- Python 3.10+
- Django 4.2+
- Django Ninja 1.0+
Install
uv add django-ninja-jsonapi
or
pip install django-ninja-jsonapipoetry add django-ninja-jsonapipdm add django-ninja-jsonapi
Quick start
1) Define a Django model and a schema
from django.db import models
from pydantic import BaseModel
class Customer(models.Model):
name = models.CharField(max_length=128)
class CustomerSchema(BaseModel):
name: str
2) Create a JSON:API view class
from django_ninja_jsonapi import ViewBaseGeneric
class CustomerView(ViewBaseGeneric):
pass
3) Register resources with ApplicationBuilder
from ninja import NinjaAPI
from django_ninja_jsonapi import ApplicationBuilder
api = NinjaAPI()
builder = ApplicationBuilder(api)
builder.add_resource(
path="/customers",
tags=["customers"],
resource_type="customer",
view=CustomerView,
model=Customer,
schema=CustomerSchema,
)
builder.initialize()
4) Mount API in Django URLs
from django.urls import path
from .api import api
urlpatterns = [
path("api/", api.urls),
]
Configuration
Set JSON:API options in Django settings:
NINJA_JSONAPI = {
"MAX_INCLUDE_DEPTH": 3,
"MAX_PAGE_SIZE": 100,
"ALLOW_DISABLE_PAGINATION": True,
}
Exported public API
from django_ninja_jsonapi import ApplicationBuilder, QueryStringManager, HTTPException, BadRequest, ViewBaseGeneric
Development
uv run ruff format src tests
uv run ruff check src tests
uv run pytest --cov=src/django_ninja_jsonapi --cov-report=term-missing
See CONTRIBUTING.md for the full contribution workflow.
Release process
Releases are automated with GitHub Actions:
- Merge conventional-commit PRs into
main. Release Pleaseopens or updates a release PR with version bump + changelog updates.- Merge the release PR to create a GitHub Release.
Publish to PyPIruns onrelease: publishedand uploads the built package to PyPI.
Workflows:
.github/workflows/release-please.yml.github/workflows/publish.yml
Required repository secrets:
REPO_ADMIN_TOKEN(used by Release Please)PYPI_API_TOKEN(used for PyPI publishing)
Test coverage
Current tests cover:
- Application builder initialization and route registration behavior
- Query-string parsing behavior
- Django ORM query-building mapping (
filter/sorttranslation) - Exception handler response shape
Notes
- This project is Django Ninja + Django ORM focused.
- SQLAlchemy-specific modules have been removed to keep the codebase simpler and consistent.
- CI runs on pull requests and pushes to
main.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_ninja_jsonapi-0.2.0.tar.gz.
File metadata
- Download URL: django_ninja_jsonapi-0.2.0.tar.gz
- Upload date:
- Size: 36.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9271de43297fdd51ba150f69647ffe25e2bec460fc0a4c3ec985d0252834f67
|
|
| MD5 |
560cdbfc04a297b6ca5369f940464199
|
|
| BLAKE2b-256 |
523f6b572bf16df7bf976a8bc9d27d295d51f1c307f3e949137706b9707758d3
|
File details
Details for the file django_ninja_jsonapi-0.2.0-py3-none-any.whl.
File metadata
- Download URL: django_ninja_jsonapi-0.2.0-py3-none-any.whl
- Upload date:
- Size: 55.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcfb72cc58db85b15519e73ad3cab0b00cf56e202ee4ce0fe3abeb376d12ab51
|
|
| MD5 |
dec156ec75cc296cdf29d8d62a623beb
|
|
| BLAKE2b-256 |
11a1a5c480d2e2fe335cce789e644c4e3820a3211dd2b08c4a4e9f6e56ea120c
|