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.

Metadata

Release files for litestar-security 0.7.1

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.7.1
File Size Uploaded Provenance Actions
litestar_security-0.7.1.tar.gz 842.7 kB With provenance Details for litestar_security-0.7.1.tar.gz

Built distribution (wheel)

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

Total release size: 1.2 MB

Release files / litestar_security-0.7.1.tar.gz

Download URL litestar_security-0.7.1.tar.gz
Size 842.7 kB
Tags Source
SHA-256 checksum
How to use checksums
db42108f11f2f96ed10b384607e8e4812d69bb44ff32de059ee6f6879687efa9
BLAKE2b-256 checksum
How to use checksums
b501f057f9d0fa8866040b3c47ecea8c6d1291b3c36100954e9436398e0535ee
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 Nov 2, 2026.

Transparency log

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

Download URL litestar_security-0.7.1-py3-none-any.whl
Size 386.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b2f889e027c9555f44b7ede504ae568b69e107449e75c8d74313d28411d069b
BLAKE2b-256 checksum
How to use checksums
c95be477ee2405756a779f1d9d2aa485e66750b02c03bfaf30a3306c3835aaa5
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 Nov 2, 2026.

Transparency log

Security for litestar-security 0.7.1

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for litestar_security-0.7.1.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 Nov 2, 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