Skip to main content

Litestar Security

Authentication and authorization for Litestar applications.

Litestar Security connects authentication providers to Litestar's middleware, dependency injection, guards, OpenAPI schema, and WebSocket lifecycle. Use local sessions or tokens, OAuth and OIDC, Google IAP, API keys, or workload JWTs without tying your application to a database library.

Quickstart

Install the package:

pip install litestar-security

Create app.py:

from litestar import Litestar, get
from litestar.di import NamedDependency

from litestar_security import (
    SecurityConfig,
    SecurityContext,
    SecurityPlugin,
    public,
)


@get("/", auth=public(), sync_to_thread=False)
def index(security_context: NamedDependency[SecurityContext]) -> dict[str, bool]:
    return {"authenticated": bool(security_context.evidence)}


app = Litestar(route_handlers=[index], plugins=[SecurityPlugin(SecurityConfig())])

Run the application:

litestar --app app:app run

Public routes must be explicit. Once an authentication provider and authorization resolver are configured, routes are protected by default and guards can enforce application permissions:

from litestar import get

from litestar_security import requires_tenant_role, required


@get(
    "/tenants/{tenant_id:str}",
    auth=required(),
    guards=[requires_tenant_role(tenant_parameter="tenant_id", roles={"owner"})],
)
async def tenant_settings(tenant_id: str) -> dict[str, str]:
    return {"tenant_id": tenant_id}

Next steps

Litestar Security supports Python 3.10 through 3.14 and is licensed under MIT.

Release files for litestar-security 0.6.0

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

Source distribution (sdist)

Source distribution for litestar-security 0.6.0
File Size Uploaded
litestar_security-0.6.0.tar.gz 831.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for litestar-security 0.6.0
File Interpreter ABI Platform
litestar_security-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / litestar_security-0.6.0.tar.gz

Download URL litestar_security-0.6.0.tar.gz
Size 831.6 kB
Tags Source
SHA-256 checksum
How to use checksums
704a4015fa7e12df1575fa59eb42e55c435580aa6104ce49e7eb89b935c967b9
BLAKE2b-256 checksum
How to use checksums
245e44281195f84008e1784b1f716bd4ff7594001af74df753294ddd2d43b0a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 19, 2026.

Transparency log

Release files / litestar_security-0.6.0-py3-none-any.whl

Download URL litestar_security-0.6.0-py3-none-any.whl
Size 382.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60091f0b52d33892ce35604376b577f0fb61076735227d58cd90135917ff7d3c
BLAKE2b-256 checksum
How to use checksums
c95f3115d01e755b8a121d95e2e5ea582aa6a2ee7155a3cccd039d58a45a0020
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

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