Skip to content

Getting started

JWT Ninja is a standard Django app. Install it, run migrations, and mount the router.

Install

uv add jwtninja
pip install jwtninja

Requires Python 3.12+ and Django 5.2.16 through 6.1 (>=5.2.16,<6.2).

Asymmetric algorithms

Asymmetric signing algorithms (RS*, ES*, PS*, EdDSA) need PyJWT's cryptography extra:

uv add "jwtninja[crypto]"
# or
pip install "jwtninja[crypto]"

Quick start

1. Add jwt_ninja to your INSTALLED_APPS:

settings.py
INSTALLED_APPS = [
    ...,
    "jwt_ninja",
]

2. Run migrations to create the Session table:

python manage.py migrate

3. Mount the router on your Ninja API and register the error handler:

api.py
from ninja import NinjaAPI
from jwt_ninja import APIError
from jwt_ninja.api import router as auth_router
from jwt_ninja.handlers import error_handler

api = NinjaAPI()
api.add_router("auth/", auth_router)
api.add_exception_handler(APIError, error_handler)

This gives you /auth/login/, /auth/refresh/, /auth/sessions/, /auth/sessions/{id}/, /auth/logout/, and /auth/logout/all/.

Next steps