drf-pyseto
A simple, secure, and modern PASETO (Platform-Agnostic Security Tokens) authentication backend for Django REST Framework (DRF), powered by pyseto.
📖 Read the Full Documentation Here
drf-pyseto utilizes the v4.local (symmetric encryption) PASETO specification, providing a more secure alternative to JWTs by preventing cryptographic agility attacks and minimizing misconfigurations.
🌟 Features
- Secure by Default: Implements PASETO
v4.localensuring robust, symmetric encryption for your tokens. - Seamless Integration: Built specifically for Django REST Framework. Drop-in replacement for traditional token or JWT authentication.
- Configurable Lifetimes: Easily manage separate lifetimes for access and refresh tokens.
- Modern Python & Django Support: Compatible with Python 3.10–3.14 and Django 4.2–6.0.
📦 Requirements
- Python >= 3.10
- Django >= 4.2
- Django REST Framework >= 3.16
- pyseto >= 1.7
🚀 Installation
Install the package via pip:
pip install drf-pyseto
⚙️ Configuration
1. Update Django Settings
Add the necessary configuration for drf-pyseto in your settings.py:
DRF_PYSETO = {
# REQUIRED: A 32-byte secret key (can be plain 32-bytes or base64url encoded)
"KEY": "<your-32-byte-secret-key-or-base64url>",
# Optional settings (defaults shown)
"ACCESS_LIFETIME": 300, # Access token lifetime in seconds (default: 5 minutes)
"REFRESH_LIFETIME": 86400, # Refresh token lifetime in seconds (default: 1 day)
"USER_ID_FIELD": "id", # User model field used as the subject
"USER_ID_CLAIM": "user_id", # Claim key for the user identifier
"TOKEN_TYPE_CLAIM": "typ", # Claim key for the token type
"AUTH_HEADER_TYPE": "Bearer", # Allowed Authorization header type
# Additional standard PASETO claims (optional)
# "ISSUER": "your-service",
# "AUDIENCE": "your-clients",
}
2. Configure DRF Authentication
Set drf_pyseto as your authentication class in settings.py:
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"drf_pyseto.authentication.PASETOAuthentication",
)
}
3. Setup Routing
Include the token endpoints in your project's urls.py:
from django.urls import path, include
urlpatterns = [
# ...
path("api/auth/", include("drf_pyseto.urls")),
# ...
]
📡 Endpoints
Once configured, the following endpoints will be available to manage your tokens (assuming you included the URLs under api/auth/):
-
Obtain Tokens:
POST /api/auth/token/- Payload:
{"username": "your_username", "password": "your_password"} - Returns format:
{"access": "v4.local....", "refresh": "v4.local...."}
- Payload:
-
Refresh Access Token:
POST /api/auth/token/refresh/- Payload:
{"refresh": "v4.local...."} - Returns format:
{"access": "v4.local...."}
- Payload:
🛠️ Development & Testing
To set up the project for development and run the test suite:
# Clone the repository
git clone https://github.com/p-r-a-v-i-n/drf-pyseto.git
cd drf-pyseto
# Install locally with testing dependencies
pip install -e ".[test]"
# Run tests
pytest
📜 License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for drf-pyseto 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| drf_pyseto-0.1.2.tar.gz | 10.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| drf_pyseto-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.2 kB
Release files / drf_pyseto-0.1.2.tar.gz
| Download URL | drf_pyseto-0.1.2.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a142f9a752a30f0f218f5ff8ffd47814bc9bf33dd4751e0855d4f9328c30829
|
|
BLAKE2b-256 checksum How to use checksums |
e80395e8021e7039ab7022e7f01f5b0af62da1bc9484146cd2c8a33a298fe8d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Apr 16, 2026.
Transparency logRelease files / drf_pyseto-0.1.2-py3-none-any.whl
| Download URL | drf_pyseto-0.1.2-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ebb4a94ea18cab429586ae65c9be77aeea1d7363433259af3e7f1278ac485d4
|
|
BLAKE2b-256 checksum How to use checksums |
0c48ac1db0c4aa77db926cdd592826502737443aed1806732db42f66564f5cb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Apr 16, 2026.
Transparency log