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 required, requires_team_role
@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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file litestar_security-0.1.0.tar.gz.
File metadata
- Download URL: litestar_security-0.1.0.tar.gz
- Upload date:
- Size: 580.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da2f1ccc03f1ee4b85f2860cd468930d2ebad6285205cf3b381120057303c4f7
|
|
| MD5 |
aeaeb141c49bdb06112fa00b6faca2d9
|
|
| BLAKE2b-256 |
0dd8211d418ddd12b132f9cc3655a5f960c1845ecb021eccb2d6aad72de1e0f9
|
Provenance
The following attestation bundles were made for litestar_security-0.1.0.tar.gz:
Publisher:
publish.yml on cofin/litestar-security
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_security-0.1.0.tar.gz -
Subject digest:
da2f1ccc03f1ee4b85f2860cd468930d2ebad6285205cf3b381120057303c4f7 - Sigstore transparency entry: 2281153985
- Sigstore integration time:
-
Permalink:
cofin/litestar-security@011582c17e44ab216fcf7c168d8da77254fd68a7 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cofin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@011582c17e44ab216fcf7c168d8da77254fd68a7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file litestar_security-0.1.0-py3-none-any.whl.
File metadata
- Download URL: litestar_security-0.1.0-py3-none-any.whl
- Upload date:
- Size: 270.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baf678c3292aa56adc32882643f35a570d5c78cd2dfbc58948d225bd578a96ad
|
|
| MD5 |
6663dee225ed4292d3c46e3658e22c18
|
|
| BLAKE2b-256 |
a21d862027494b69629d7206d0895f14da127c3e5b6e9bc008060eeae9a8dea1
|
Provenance
The following attestation bundles were made for litestar_security-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on cofin/litestar-security
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_security-0.1.0-py3-none-any.whl -
Subject digest:
baf678c3292aa56adc32882643f35a570d5c78cd2dfbc58948d225bd578a96ad - Sigstore transparency entry: 2281154004
- Sigstore integration time:
-
Permalink:
cofin/litestar-security@011582c17e44ab216fcf7c168d8da77254fd68a7 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cofin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@011582c17e44ab216fcf7c168d8da77254fd68a7 -
Trigger Event:
release
-
Statement type: