django-ninja-expose
Add @expose() to a Django model. Get a REST API.
from django.db import models
from django_ninja_expose import expose
@expose()
class Task(models.Model):
title = models.CharField(max_length=200)
completed = models.BooleanField(default=False)
# urls.py
from django.urls import path
from ninja import NinjaAPI
from django_ninja_expose import mount
api = NinjaAPI()
mount(api) # or api.add_router("", get_router())
urlpatterns = [path("api/", api.urls)]
You get GET/POST /api/Task, GET/PUT/PATCH/DELETE/HEAD /api/Task/{pk}, Django-native
filtering (?title__icontains=x&completed=false), Ninja pagination and OpenAPI docs.
@expose(path=None, methods=None, fields=None, query=None)
None = automatic, [] = none, list = explicit restriction.
| arg | None |
[] |
list |
|---|---|---|---|
path |
class name | n/a | URL path |
methods |
all six (HEAD is never implied) |
no operations | only these |
fields |
all concrete fields + M2M | no fields | only these |
query |
all exposed fields | filtering disabled | only these (subset of fields) |
Invalid configuration fails at import time (ExposeConfigurationError and subclasses);
duplicate paths fail when the router is built.
Security warning
@expose() exposes model data and CRUD operations by default, with no authentication.
Explicitly restrict methods, fields and query for production APIs, and add auth
on your NinjaAPI.
Notes
- Foreign keys and many-to-many fields are represented by primary keys (no nesting).
- Filters accept Django lookups/transforms on whitelisted fields only; relationship traversal is rejected (HTTP 400).
- Writes run Django's
full_clean(); non-editable fields (e.g.auto_now_add) are never writable.
Metadata
Release files for django-ninja-expose 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_ninja_expose-0.1.0.tar.gz | 7.3 kB | Without provenance | Details for django_ninja_expose-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_ninja_expose-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for django_ninja_expose-0.1.0-py3-none-any.whl |
Total release size: 18.6 kB
Release files / django_ninja_expose-0.1.0.tar.gz
| Download URL | django_ninja_expose-0.1.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
acb102d4aeaf063cff66b6165dc8e2eab2321d4e409d584b4bd8d929f0fa205a
|
|
BLAKE2b-256 checksum How to use checksums |
1ef93dbd032138c83b09285e2a20a944fffdca48479be38fc33db4bf187f254d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / django_ninja_expose-0.1.0-py3-none-any.whl
| Download URL | django_ninja_expose-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2c67507a810d165088d2009a7bed44235c373db54cc58b15dca283da6aefbe8
|
|
BLAKE2b-256 checksum How to use checksums |
c97d93f8122b698936ac047f799d91ee9800b51b7700d84c4e604e1302065986
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for django-ninja-expose 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.