Repository navigation
Home
Kyvex edited this page Aug 30, 2026
·
2 revisions
django-tenant-apikeys is a small, framework-agnostic package for issuing API keys to the tenants/organizations in a multi-tenant Django app — prefix + hashed secret, per-key scopes, expiration, and throttled last-used tracking, with first-class Django REST Framework support and a documented Django Ninja recipe. For install instructions and the full API reference, start with the README.
This wiki goes deeper on specific topics than the README does. Suggested reading order below; jump straight to whichever one you need otherwise.
-
Django multi-tenant API key authentication — the core model: why multi-tenant API keys need more than
TokenAuthentication, and how the prefix+hash, scopes, expiry, andlast_used_atfields work together. - django-tenant-apikeys vs djangorestframework-api-key: which one do you need — a factual comparison if you're deciding between the two.
-
Scoping API keys per tenant in Django REST Framework —
has_scope(),HasAPIKeyScope, and designing a scope taxonomy that ages well. - Testing a custom DRF authentication backend with pytest-django — how the package's own test suite proves every rejection path, as a template for testing your own auth backend.
-
Django Ninja API key auth without DRF — the framework-agnostic core wired into a Ninja
APIKeyHeader, line by line.
-
Rotating and expiring API keys in Django without breaking existing clients — the overlap pattern: issue new, grace-period the old one, verify the cutover with
last_used_at. -
Throttled last_used_at tracking: avoiding a DB write on every authenticated request — how
record_usage()avoids turning a hot endpoint into a write on every request. - One-time secret reveal in Django admin: the pattern behind save_model — how the admin shows a new secret exactly once, and how to extend it safely for your own concrete model.
- Multi-tenant Django patterns: shared-schema vs schema-per-tenant, and where API keys fit — where this package's shared-schema design fits, and what changes in a schema-per-tenant setup.
- A security checklist for storing API keys in Django — every security decision the package made, as a general checklist for storing API keys in Django whether you use this package or not.
- Full README and API reference
- A working end-to-end example project
- Issues — bug reports and feature requests
- Changelog