A token manager for Python
Project description
pytokenx
pytokenx 是一个简单易用的 Python Token 管理器。它提供了生成、验证和管理 token 的功能。
特性
- 生成安全的随机 token
- 支持 token 过期时间设置
- 同时支持多种token类型
- token数据的持久化,目前支持文件、以及SQLAlchemy,也可以用户自定义
安装
pip install pytokenx
使用
from pytoken import TokenManager, FileTokenStorage, SQLAlchemyTokenStorage
# 使用文件存储
token_manager = TokenManager(FileTokenStorage("tokens.json"))
# sqlite存储
# token_manager = TokenManager(SQLAlchemyTokenStorage(connection_string="sqlite:///test.db"))
token = token_manager.generate_token() # 生成token
print(token)
token_data = token_manager.validate_token(token) # 验证token
if token_data:
print(token_data)
else:
print("token 无效")
token_manager.delete_token(token) # 删除token
# 使用装饰器
@token_validator(token_manager)
def my_function(token):
print(token)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytokenx-0.3.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file pytokenx-0.3.tar.gz
.
File metadata
- Download URL: pytokenx-0.3.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f2d404bc10d6ad8bf090fbf2d9d797f656352df2091e08a01b8161abc9520ad |
|
MD5 | 6cf9f232d11ba9b4a474f764cc11f7f1 |
|
BLAKE2b-256 | b506e65ce59121a5e63ad894e5a36ed838f7cc779c63be0c76b40df746e12490 |
File details
Details for the file pytokenx-0.3-py3-none-any.whl
.
File metadata
- Download URL: pytokenx-0.3-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 152bf94c7603c5dbd21bf4b2c1ea1e71385f2fc3323fe31599ce83ef3fa5ab2f |
|
MD5 | 635dedce2cff41ff178ab5aec6478cbd |
|
BLAKE2b-256 | ddccb9c79b2aa939a511a21b897f339139b3abd0b077c0e39f1feaf6f9d9599f |