Ninja API Key
API Key authentication for Django Ninja.
This is a fork from django-ninja-apikey.
Key Features:
- Easy integration into your projects
- Well integrated with the Admin interface
- Secure API keys due to hashing
- Works with the standard user model
Installation
pip install ninja-api-key
How to use
- Add
ninja_apikeyto your installed apps in your Django project:
# settings.py
INSTALLED_APPS = [
# ...
"ninja_apikey",
]
- Apply migrations
python manage.py migrate
-
Secure
a. the whole API
# api.py from ninja import NinjaAPI from ninja_apikey.security import APIKeyAuth # ... api = NinjaAPI(auth=APIKeyAuth()) # ... @api.get("/secure_endpoint") def secure_endpoint(request): return f"Hello, {request.user}!"
b. an specific endpoint
# api.py from ninja import NinjaAPI from ninja_apikey.security import APIKeyAuth # ... auth = APIKeyAuth() api = NinjaAPI() # ... @api.get("/secure_endpoint", auth=auth) def secure_endpoint(request): return f"Hello, {request.user}!"
-
ninja-api-key uses
settings.PASSWORD_HASHERSto hash the API keys. Django's defaultPBKDF2PasswordHashermay be slow depending on the number of iterations. You can change thesettings.PASSWORD_HASHERSto use a faster (but less secure) one. ninja-api-key provides aSHA256PasswordHasher.# settings.py PASSWORD_HASHERS = [ "ninja_apikey.hashers.SHA256PasswordHasher", # others ]
⚠️ Keep in mind that this will affect Django authentication as a whole, not just ninja-api-key.
Changelog
See CHANGELOG.md for a detailed history of changes and releases.
Contributing
Contributions are welcome; feel free to open an Issue or Pull Request.
git clone https://github.com/lucasrcezimbra/ninja-api-key
cd ninja-api-key
python -m venv .venv
source .venv/bin/activate
pip install .[test]
pre-commit install
make test
Metadata
Release files for ninja-api-key 2.0.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 | |
|---|---|---|---|
| ninja_api_key-2.0.0.tar.gz | 8.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ninja_api_key-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.1 kB
Release files / ninja_api_key-2.0.0.tar.gz
| Download URL | ninja_api_key-2.0.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3dbc2390d13671ff336377068e83504fa1819a2fe6acbc58ce8afe00a290527c
|
|
BLAKE2b-256 checksum How to use checksums |
b5752b453e2055beef8bd1e3b9a66513b4487325736db4f5d85b03e474cdc9a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 6, 2026.
Transparency logRelease files / ninja_api_key-2.0.0-py3-none-any.whl
| Download URL | ninja_api_key-2.0.0-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6da7d4900953747d2b8f7cca7de1d005eb3996cd2d9a2032d5eaaddd5eed267b
|
|
BLAKE2b-256 checksum How to use checksums |
65268a9982dc656e2c905bda8438299ccfd75c7f1957c78758f7f602f0a7e23a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 6, 2026.
Transparency log