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_team_role, required
@get(
"/teams/{team_id:str}",
auth=required(),
guards=[requires_team_role(team_parameter="team_id", roles={"owner"})],
)
async def team_settings(team_id: str) -> dict[str, str]:
return {"team_id": team_id}
Next steps
- Read the documentation
- Choose an authentication provider
- Configure local accounts
- Run the API, team, and local-auth examples
- Browse the API reference
Litestar Security supports Python 3.10 through 3.14 and is licensed under MIT.
Release files for litestar-security 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| litestar_security-0.5.0.tar.gz | 825.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| litestar_security-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.2 MB
Release files / litestar_security-0.5.0.tar.gz
| Download URL | litestar_security-0.5.0.tar.gz |
|---|---|
| Size | 825.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d0b814860c509e7c5b61bec757fc940787408f7285f652e20f78b154ff8e8d5
|
|
BLAKE2b-256 checksum How to use checksums |
957a5345960059ca8eb1081f6aa7e2d505c232e20d0bc05ff26c503a071601c8
|
| 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 16, 2026.
Transparency logRelease files / litestar_security-0.5.0-py3-none-any.whl
| Download URL | litestar_security-0.5.0-py3-none-any.whl |
|---|---|
| Size | 379.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66a992e85c9fc88803043f8ae2f02960b0b8580ad5ab367d4febe70d5ed2d262
|
|
BLAKE2b-256 checksum How to use checksums |
778a2901c989589023671ff2d1ef1918fb211782151ddcbac68aebdf938823b3
|
| 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 16, 2026.
Transparency log