Skip to main content

kernia

Framework-agnostic authentication core for Python: email/password, sessions, OAuth, and a plugin system. Wire-compatible with the official Better Auth JavaScript client, so an existing frontend can talk to a Kernia server unchanged.

Kernia is a framework-agnostic authentication library for Python. See kernia.dev.

Features

  • Email/password sign-up and sign-in with Argon2id hashing
  • HMAC-signed session cookies and CSRF/trusted-origins protection
  • OAuth 2.0 social sign-in with 35 built-in providers plus generic OAuth
  • A plugin system: organizations, admin, magic links, email OTP, two-factor, JWT, OpenAPI, and more
  • One schema across memory, SQLAlchemy, and MongoDB adapters
  • Wire-compatible with the official Better Auth JavaScript client

Installation

pip install kernia

Adapters, server integrations, and optional plugins ship in the same distribution as extras. Install only what you use:

pip install "kernia[fastapi,sqlalchemy]"

Available extras: jwt, passkey, sso, oauth-provider, stripe, mcp, sqlalchemy, mongo, redis, fastapi, starlette, django, and all. Each pulls in its own third-party requirements; the import paths are unchanged (from kernia_fastapi import mount_kernia, from kernia_sqlalchemy import sqlalchemy_adapter, and so on).

Usage

import os
from kernia.auth import init
from kernia.plugins import email_and_password
from kernia.plugins.organization import organization
from kernia.types.init_options import KerniaOptions
from kernia_memory_adapter import memory_adapter

auth = init(
    KerniaOptions(
        database=memory_adapter(),
        secret=os.environ["KERNIA_SECRET"],
        base_url="http://localhost:8000",
        base_path="/api/auth",
        plugins=[email_and_password(), organization()],
    )
)

Mount it on a FastAPI app with kernia-fastapi:

from fastapi import Depends, FastAPI
from kernia_fastapi import mount_kernia, require_session

app = FastAPI()
mount_kernia(app, auth)  # serves /api/auth/*

@app.get("/me")
async def me(session=Depends(require_session)):
    return {"user_id": session.user_id}

Point the official Better Auth JavaScript client at /api/auth and it works without a shim.

Documentation

Full documentation at kernia.dev/docs. Source at github.com/advantch/kernia.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kernia-0.1.0.tar.gz (383.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kernia-0.1.0-py3-none-any.whl (426.8 kB view details)

Uploaded Python 3

File details

Details for the file kernia-0.1.0.tar.gz.

File metadata

  • Download URL: kernia-0.1.0.tar.gz
  • Upload date:
  • Size: 383.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kernia-0.1.0.tar.gz
Algorithm Hash digest
SHA256 161442a8c3f924bdc8c4704d8e3c31f8602ff4e79ba0fe17baea6a44e3a1a219
MD5 218004f4143f2dff60d0aa1afad40ff7
BLAKE2b-256 9d82a30df14777689dff38afe8b41de58be958f9ff1546b9f2e4da0ecb4d91bb

See more details on using hashes here.

File details

Details for the file kernia-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kernia-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 426.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kernia-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8174e122c5d7f06c65ec26b24b729a23dcb4968fdd5023738939bd847c463449
MD5 3635df2818f4c3e9d779d6a40c711096
BLAKE2b-256 a51781cff054e227adfd4f4cc025499921d584810b8140d301ee4c4672ed2c46

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page