Skip to main content

django-authkit

django-authkit is a reusable Django package that provides an auth API layer built on Django's own authentication system.

The PyPI distribution name is django-authkit-api because the shorter django-authkit name is too similar to an existing PyPI project. The Python import path and Django app label remain authkit.

The package uses:

  • A package-owned custom user model configured as AUTH_USER_MODEL = "authkit.User".
  • Django's built-in auth flows, password hashing, authentication backends, admin compatibility, permissions, groups, and sessions where appropriate.
  • Django Group as the role primitive.
  • Django Permission for permission management.
  • Django REST Framework for APIs.
  • drf-spectacular for OpenAPI and Swagger integration.
  • SimpleJWT for token-based API authentication.

This repository also contains an example_django_app for local demonstration. That example app is intentionally outside the installable package.

Clone And Run The Example App

Prerequisites:

  • Docker with Docker Compose.
  • make.

Clone the repo, then run the full example bootstrap and server flow:

git clone https://github.com/Imam-Hossain-45/django-authkit.git
cd django-authkit
make example-dev

That command will:

  • create .env from .env.example if it does not exist
  • build the example app image
  • run migrations
  • create a reusable local superuser if missing
  • start the example Django app on port 8010

Open:

Default local admin credentials come from .env.example:

email: admin@example.com
password: admin12345

For a step-by-step flow instead:

cp .env.example .env
make example-build
make example-migrate
make example-superuser
make example-up

Useful example commands:

make example-bootstrap
make example-logs
make example-shell
make example-down

Installation

Install from PyPI after a release is published:

python -m pip install django-authkit-api

Install from a local checkout:

python -m pip install /path/to/django-authkit

Install in editable mode while developing:

python -m pip install -e /path/to/django-authkit

Install from a git repository:

python -m pip install "django-authkit-api @ git+https://github.com/Imam-Hossain-45/django-authkit.git"

For a private or personal repository, replace the URL with your actual git remote:

python -m pip install "django-authkit-api @ git+https://github.com/<owner>/django-authkit.git"

For repeatable application installs, pin a tag or commit:

python -m pip install "django-authkit-api @ git+https://github.com/<owner>/django-authkit.git@v0.1.0"

Install optional dependency groups when needed:

python -m pip install "django-authkit-api[social] @ git+https://github.com/Imam-Hossain-45/django-authkit.git"
python -m pip install -e "/path/to/django-authkit[dev,docs]"

The installable package only includes authkit from src/authkit. The tests, docs, and example_django_app directories are repository assets and are excluded from package distribution.

Development Commands

Install the package with development dependencies:

python -m pip install -e ".[dev]"

Common commands:

make lint
make format
make test
make coverage
make build

Check built package artifacts before publishing:

python -m twine check dist/*

Example app commands:

make example-dev
make example-migrate
make example-superuser
make example-down

Minimal Integration

For a fresh Django project, install the package, configure the custom user model before the first migration, include the package URLs, then run migrations:

python -m pip install "django-authkit-api @ git+https://github.com/Imam-Hossain-45/django-authkit.git"
# settings.py
INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "rest_framework",
    "rest_framework_simplejwt.token_blacklist",
    "drf_spectacular",
    "authkit",
]

AUTH_USER_MODEL = "authkit.User"

REST_FRAMEWORK = {
    "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "rest_framework_simplejwt.authentication.JWTAuthentication",
    ),
}
# urls.py
from django.urls import include, path

urlpatterns = [
    path("", include("authkit.urls")),
]
python manage.py migrate

Consumer Django Setup

1. Install From Git

Use a direct git install for open-source or private git distribution:

python -m pip install "django-authkit-api @ git+https://github.com/Imam-Hossain-45/django-authkit.git"

For a specific branch, tag, or commit:

python -m pip install "django-authkit-api @ git+https://github.com/Imam-Hossain-45/django-authkit.git@main"

2. Add Required Apps

Add Django's auth/admin dependencies, DRF, SimpleJWT blacklist support, drf-spectacular, and authkit to INSTALLED_APPS:

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",

    "rest_framework",
    "rest_framework_simplejwt.token_blacklist",
    "drf_spectacular",

    "authkit",
]

3. Set The Custom User Model

Configure the package-owned user model before running migrations:

AUTH_USER_MODEL = "authkit.User"

authkit.User is implemented under authkit.users.models.User and exported through the installed Django app label as authkit.User.

4. Configure DRF And drf-spectacular

If the consuming project does not already configure DRF schema generation, add:

REST_FRAMEWORK = {
    "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "rest_framework_simplejwt.authentication.JWTAuthentication",
    ),
}

SPECTACULAR_SETTINGS = {
    "TITLE": "My Project API",
    "DESCRIPTION": "Project API schema.",
    "VERSION": "1.0.0",
}

django-authkit also exposes package-level OpenAPI metadata through the AUTHKIT setting:

AUTHKIT = {
    "API_PREFIX": "authkit/",
    "OPENAPI_TITLE": "My Project Auth API",
    "OPENAPI_DESCRIPTION": "Authentication APIs provided by django-authkit.",
    "OPENAPI_VERSION": "1.0.0",
}

Administrative and management endpoints such as /authkit/users/, /authkit/roles/, /authkit/permissions/, and /authkit/audit-logs/ use Django permissions and can be configured to require staff status, superuser status, or permission-only access:

AUTHKIT = {
    "ADMIN_API_REQUIRE_STAFF": True,
    "ADMIN_API_REQUIRE_SUPERUSER": False,
}

Defaults preserve backward compatibility:

  • ADMIN_API_REQUIRE_STAFF = True
  • ADMIN_API_REQUIRE_SUPERUSER = False

Examples:

  • Default behavior: is_staff plus the required Django permission(s)
  • Permission-only behavior: set ADMIN_API_REQUIRE_STAFF = False
  • Superuser-only management APIs: set ADMIN_API_REQUIRE_SUPERUSER = True

5. Include Package URLs

Include the package URLs once in the consuming project's root URLconf. The package applies its own configurable prefix.

from django.urls import include, path

urlpatterns = [
    path("", include("authkit.urls")),
]

By default, this exposes:

  • /authkit/
  • /authkit/auth/
  • /authkit/users/
  • /authkit/roles/
  • /authkit/permissions/
  • /authkit/password-reset/
  • /authkit/verification/
  • /authkit/social-auth/
  • /authkit/audit-logs/
  • /authkit/schema/
  • /authkit/docs/swagger/
  • /authkit/docs/redoc/

To move the package API under another path, change AUTHKIT["API_PREFIX"]:

AUTHKIT = {
    "API_PREFIX": "api/auth/",
}

With that setting, the package info endpoint becomes /api/auth/.

6. Run Migrations

Run migrations after AUTH_USER_MODEL and INSTALLED_APPS are configured:

python manage.py migrate

Create an admin user with Django's normal command:

python manage.py createsuperuser

Main Auth API Surface

django-authkit is intended to become the main authentication API surface for the consuming Django project. Consumer projects should integrate auth, users, roles, permissions, verification, password reset, social auth, and audit-log read APIs through the package URLs.

The package still uses Django's built-in auth internals rather than replacing them. Roles are Django Group records, permissions are Django Permission records, passwords use Django password hashers, and admin/session compatibility stays aligned with Django.

Migration Caveat

Set this before the consuming project's first migration:

AUTH_USER_MODEL = "authkit.User"

Changing AUTH_USER_MODEL after a Django project already has migrations and tables is difficult and project-specific. django-authkit does not try to hide or automate that migration because Django treats the user model as a foundational schema decision.

Google Social Auth

Install the social optional dependencies when using Google login:

python -m pip install "django-authkit-api[social] @ git+https://github.com/Imam-Hossain-45/django-authkit.git"

Create an OAuth 2.0 Client ID in Google Cloud Console for the consuming project, then configure:

AUTHKIT = {
    "SOCIAL_AUTH_GOOGLE_CLIENT_ID": "your-google-oauth-client-id.apps.googleusercontent.com",
    "SOCIAL_AUTH_ALLOW_SIGNUP": True,
    "SOCIAL_AUTH_ALLOW_ACCOUNT_LINKING": True,
    "SOCIAL_AUTH_MARK_VERIFIED_EMAIL": True,
}

Clients should obtain a Google ID token using Google's OAuth/OpenID Connect flow, then exchange it with:

POST /authkit/social-auth/google/token/

Request body:

{
  "id_token": "google-id-token"
}

Provider metadata is available at:

  • /authkit/social-auth/providers/
  • /authkit/social-auth/providers/google/

Status

Reusable package foundation with auth, user, role, permission, password reset, verification, social auth, audit log, and OpenAPI endpoints.

Metadata

Release files for django-authkit-api 0.1.2

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-authkit-api 0.1.2
File Size Uploaded Provenance Actions
django_authkit_api-0.1.2.tar.gz 38.2 kB With provenance Details for django_authkit_api-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-authkit-api 0.1.2
File Interpreter ABI Platform Actions
django_authkit_api-0.1.2-py3-none-any.whl Python 3 none any Details for django_authkit_api-0.1.2-py3-none-any.whl

Total release size: 91.8 kB

Release files / django_authkit_api-0.1.2.tar.gz

Download URL django_authkit_api-0.1.2.tar.gz
Size 38.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3a73cff5cad37129d16a4a2ea9de7cff1051a88a741a47b7200180dc3a56a0ac
BLAKE2b-256 checksum
How to use checksums
822e29c54463c7d9209f2df395e2cb137310d8a7c9c5249d129d5bb7eb905365
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 10, 2026.

Transparency log

Release files / django_authkit_api-0.1.2-py3-none-any.whl

Download URL django_authkit_api-0.1.2-py3-none-any.whl
Size 53.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfadcfbfc9f88ae883716f71002774f5f4b8730a3901378e4fd735db6a1ae636
BLAKE2b-256 checksum
How to use checksums
4452fee4a2c88bbe122034ef4add8fc12e9b03650490e5f39d1e96e5f375d305
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 10, 2026.

Transparency log

Security for django-authkit-api 0.1.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_authkit_api-0.1.2.tar.gz

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 May 10, 2026.

Transparency log

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.

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