JWT library implemented in Rust for Python
Project description
CipherToken
CipherToken is a modern, high-performance Python library for cryptography and JWT (JSON Web Token) management.
It is implemented in Rust using PyO3, providing both speed and security for generating, encoding, decoding, and verifying tokens.
The library is designed to be modular, organized into submodules for secret management, time utilities, algorithms, and token handling.
It supports both synchronous and asynchronous operations
Library Overview
CipherToken is structured into the following main parts:
1. secret Module
Handles key generation for symmetric (HMAC) and asymmetric (RSA) algorithms:
secret_key()– Generate a random HMAC key (default 32 bytes)secret_key_with_size(size: int)– Generate HMAC key with a custom sizegenerate_hmac_secret(size: int)– Generate an HMAC secret keygenerate_hmac_secret_async(size: int)– Async version of HMAC key generationgenerate_rsa_keypair(bits: Optional[int] = 2048)– Generate RSA private/public key pair
2. time Module
Provides utility functions for time conversion and timestamps:
now()– Current UNIX timestampseconds(n: int)– Convert n seconds to secondsminutes(n: int)– Convert n minutes to secondshours(n: int)– Convert n hours to secondsdays(n: int)– Convert n days to secondsweeks(n: int)– Convert n weeks to seconds
3. utils Module
Contains useful constants:
DEFAULT_SECRET_SIZE– Default key sizeMIN_SECRET_SIZE– Minimum allowed key sizeTOKEN_ACCESS– Access token typeTOKEN_REFRESH– Refresh token type
4. algorithms Module
Defines algorithm constants for token signing:
- HMAC:
HS256,HS384,HS512 - RSA:
RS256,RS384,RS512 - ECDSA:
ES256,ES384 - RSA-PSS:
PS256,PS384,PS512 - Edwards Curve:
EDDSA
5. CipherToken Class
Main class for managing JWTs:
- Constructor:
from ciphertoken import CipherToken
CipherToken(secret: str, algorithm: str, access_ttl: int, refresh_ttl: int)
Synchronous methods:
access(user_id: int, extra_payload: Optional[dict] = None) -> str
refresh(user_id: int, extra_payload: Optional[dict] = None) -> str
decode(token: str) -> dict
verify(token: str) -> bool
rotation(refresh_token: str, extra_payload: Optional[dict] = None) -> Tuple[str, str]
inspect(token: str) -> dict
remaining_time(token: str) -> Optional[int]
algorithm_name() -> str
Asynchronous methods:
await access_async(user_id: int, extra_payload: Optional[dict] = None) -> str
await refresh_async(user_id: int, extra_payload: Optional[dict] = None) -> str
await decode_async(token: str) -> dict
await verify_async(token: str) -> bool
await rotation_async(refresh_token: str, extra_payload: Optional[dict] = None) -> Tuple[str, str]
Helper Functions:
is_jwt_format(token: str) – Check if a string is a valid JWT
validate_jwt_format(token: str) – Validate JWT structure
Installation
CipherToken is available via PyPI. Install it with:
pip install ciphertoken
Usage Example
from ciphertoken.secret import secret_key
from ciphertoken import CipherToken
from ciphertoken.time import minutes, days
from ciphertoken.utils import TOKEN_REFRESH
from ciphertoken.algorithms import HS256
# Generate a secret key
key = secret_key()
# Create a CipherToken instance
token = CipherToken(secret=key, algorithm=HS256, access_ttl=minutes(10), refresh_ttl=days(7))
# Generate access and refresh tokens
access_token = token.access(user_id=123)
refresh_token = token.refresh(user_id=123)
# Verify and decode tokens
payload = token.decode(access_token)
is_valid = token.verify(access_token)
# Async usage
import asyncio
async def generate_async_token():
access_token = await token.access_async(user_id=123)
payload = await token.decode_async(access_token)
return payload
asyncio.run(generate_async_token())
Implementation Notes
-
Built in Rust using PyO3 for maximum speed and memory safety
-
Supports synchronous and asynchronous workflows
-
Fully modular: secret, time, utils, algorithms, and CipherToken class
-
Secure key handling with HMAC and RSA support
-
Easily extendable for additional algorithms
Summary
CipherToken is a modern, Rust-backed Python library for authentication and JWT management. It is ideal for web APIs, microservices, or any system that requires secure token generation, verification, and rotation.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
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 ciphertoken-0.1.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 999.5 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36422cd7f25df3762a2995dcebb099b8a832df59c58fbc4518e4981c8aa956f5
|
|
| MD5 |
8df4eab66969888d43f3815dbc0dc2c6
|
|
| BLAKE2b-256 |
21ea375ce2e8be58f9aee9399c5d2904c618d53481d343f58837a732a2866b69
|
File details
Details for the file ciphertoken-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53cdce773bf1ea6703e40ccc03ee7c31de36dbac550b899f723b7d5f086f6bec
|
|
| MD5 |
ba9c8e90a924c8696157d528bab6bafe
|
|
| BLAKE2b-256 |
121adff8a6d02a4f69deb3b7a3997821fc2ec85a29083dbeb80393937d4485d3
|
File details
Details for the file ciphertoken-0.1.1-cp312-cp312-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp312-cp312-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3c475cacbcd8c81da835a1074098ba147a394ef8854038d698a46fd13e514ed
|
|
| MD5 |
d5a6698f0bb2b123b1748c1ca86cc834
|
|
| BLAKE2b-256 |
8f8e16282a8f03c5f86655a2fd770a2cd84d8af4171ed0d5237e548ba612cdf6
|
File details
Details for the file ciphertoken-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b226058ea10ed63c9f4738470c2ae21cb52f1d74baff8285ca672af3c39d0e57
|
|
| MD5 |
72483590d09e661cc9c6602ac3c64a4d
|
|
| BLAKE2b-256 |
4c715cb736c4145d7ccfc4d458828d5c07e3d37f14a45d5745f7e79ab4513331
|
File details
Details for the file ciphertoken-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cb19123163f462b205a6da54f9f6039778ad4ae69aea07942d1d293606d0a68
|
|
| MD5 |
1a09714e9a703b1b4f3163be81ffcf7a
|
|
| BLAKE2b-256 |
011668f77a1be4565056f40da78182b88a068f874eb63a766ea01887f937b657
|
File details
Details for the file ciphertoken-0.1.1-cp312-cp312-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp312-cp312-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cc9003f5907312a0e503c69ee7adadb3529f877ea6a81cf3334d195c3ba0901
|
|
| MD5 |
983f46fd313eb5e0fb226ad42129c155
|
|
| BLAKE2b-256 |
6094dd764676b5657955e3195dd1547547918f4dad2f0c243ee6982a0c02d185
|
File details
Details for the file ciphertoken-0.1.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0b795ab11d4b8f004b21f507865a34ce24194f4ad755558fbb4a72fba18c449
|
|
| MD5 |
763317fd659e39a6a59a29d1cb355d6a
|
|
| BLAKE2b-256 |
b4075994b2b24dcd4c569e04c2924db0302561d4cc859cbf833b728e59ef4f84
|
File details
Details for the file ciphertoken-0.1.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 997.8 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
922aa487e4d4aa665b62c4e2e481ea28171d4aa969076655c6e4799c3e6da7f4
|
|
| MD5 |
5946de1d62366116e56cd3e2709b9bdf
|
|
| BLAKE2b-256 |
492f0f9a098f5600ec590811b397a4a74c89dee1bcb63aa52efb90887d195395
|
File details
Details for the file ciphertoken-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.11, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67e37402b01d1e9a5ed16d6f60f92f8b64b57960ed3dc82db088a565e16b9fab
|
|
| MD5 |
b23bb6f69e6b01ad9b84f72b4c8ffd0a
|
|
| BLAKE2b-256 |
e3b85741090bb838ee212437054e679bae5c7b4fc3fab6c758c88f9e78c710bf
|
File details
Details for the file ciphertoken-0.1.1-cp311-cp311-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp311-cp311-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.11, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6eeffd6a1e97b4a1545d41e800d6f411eee3a8c703a51d77cc6335552d8383b8
|
|
| MD5 |
9979d3415ad9b3a855611a1d22afeddd
|
|
| BLAKE2b-256 |
f315375e760a7f2ebaa47f9bf62ecc37c1434e7d46c14ff555c16ac336e0f46d
|
File details
Details for the file ciphertoken-0.1.1-cp311-cp311-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d83c9407d2ac43724f23d0146b95d0a7f03e541e00ee408eac21e205483fb147
|
|
| MD5 |
bfb7792b88a1845be6b874e61699c0e2
|
|
| BLAKE2b-256 |
02014ec33ba690be7d7bab5f038911aa1dae6be144d8af61b62f9908c9817b32
|
File details
Details for the file ciphertoken-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f275bc65e726ec0d4ebd4212b76b5978902621a1df9505ea4a3119c1ed9bec54
|
|
| MD5 |
67ebe6defa1402a5c21546a260269419
|
|
| BLAKE2b-256 |
b837bb859ab4b1cfb521808f952f5c5728bf22d3e296d4442f157395b622249b
|
File details
Details for the file ciphertoken-0.1.1-cp311-cp311-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp311-cp311-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22a848fc775c463404587308f8751a6228c906cbb1b4a76b21ba94953c805cbe
|
|
| MD5 |
d40a40d34e3926b6235af8b5ec70c43b
|
|
| BLAKE2b-256 |
2572a48a81f0306425006a4ced7ee380edc6e6380f470343b7809274b8be6a4a
|
File details
Details for the file ciphertoken-0.1.1-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: ciphertoken-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e344d500f57ead2eb8744680cd492444f54157342b63ba016fde2d6e461aaa2
|
|
| MD5 |
499344dd66828393fe60fdbf8d4421ab
|
|
| BLAKE2b-256 |
bf5bf31fdabf8f60a48070a3618d851096a730d74c11d9ac6b2b2b0333a2521b
|