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.0.1.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file pytokenx-0.0.1.tar.gz
.
File metadata
- Download URL: pytokenx-0.0.1.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 | a1d8dc21f98854815ff88f405268e43675542163245822f5910eebaa3952fa18 |
|
MD5 | 1444274b803ce27da2d9a8f8cdf779ce |
|
BLAKE2b-256 | 0b70481ccb9f454c31b225509ecb9f6b0d033c00e33d06838daae9482efb297e |
File details
Details for the file pytokenx-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pytokenx-0.0.1-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 | a24dec4cfd0fdd8ba30e55a8ae431bf2c506cc787fc3e438b72fc79a103bd656 |
|
MD5 | 909a209018ad491c5285b3b8f528d3a6 |
|
BLAKE2b-256 | e9d08baa2e5ebd470b3e422adf599d7b259c724033c3361711ce35b169941b64 |