Skip to main content

Django Ninja APIKey

Easy to use API key authentication for Django Ninja REST Framework


This is an unofficial Django app which makes it easy to manage API keys for the Django Ninja REST Framework.

Key Features:

  • Easy integration in your projects
  • Well integrated in the admin interface
  • Secure API keys due to hashing
  • Works with the standard user model

Installation

pip install django-ninja-apikey

Usage

Add ninja_apikey to your installed apps in your django project:

# settings.py

INSTALLED_APPS = [
    # ...
    "ninja_apikey",
]

Run the included migrations:

python manage.py migrate

Secure an api endpoint with the API keys:

# 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}!" 

Or secure your whole api (or a specific router) with the API keys:

# 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}!" 

You can create now API keys from django's admin interface.

License

This project is licensed under the terms of the MIT license.

Release files for django-ninja-apikey 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-ninja-apikey 0.2.1
File Size Uploaded
django-ninja-apikey-0.2.1.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-ninja-apikey 0.2.1
File Interpreter ABI Platform
django_ninja_apikey-0.2.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 18.3 kB

Release files / django-ninja-apikey-0.2.1.tar.gz

Download URL django-ninja-apikey-0.2.1.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c7559a52b55ab9cc62005248cf55989e9509d47a0f7d1800d9d7257f64e01c54
BLAKE2b-256 checksum
How to use checksums
7dc1231060988ee43426684e0ea03b4ccc2c15271d719cea7879e6a6ac43627f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.26.0

Release files / django_ninja_apikey-0.2.1-py2.py3-none-any.whl

Download URL django_ninja_apikey-0.2.1-py2.py3-none-any.whl
Size 7.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7abc22ec871467d80c8f37e311b5f968f4f489258182c302451b2420593c3bb4
BLAKE2b-256 checksum
How to use checksums
03f0962918a8bf77f1cec5ce148178be9b3eecd1da128b031a7a34f52f0223dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.26.0

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page