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.1.tar.gz
(5.4 kB
view details)
Built Distribution
File details
Details for the file pytokenx-0.1.tar.gz
.
File metadata
- Download URL: pytokenx-0.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30614634aa34f783390a6508f19df1b441eb48198bae5204e1384a7fa008da0f |
|
MD5 | 31a0843af26a460e1830897529be5e0e |
|
BLAKE2b-256 | 27072c4635fb3e7f38c97ba9a39b6144f1658897a16ef691ae8a8e506d7a7298 |
File details
Details for the file pytokenx-0.1-py3-none-any.whl
.
File metadata
- Download URL: pytokenx-0.1-py3-none-any.whl
- Upload date:
- Size: 7.7 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 | 9a6705ca3c7b59591b628786f9a7873ae741c1979831d6c8f02c42834013ee09 |
|
MD5 | 463483ff4548fe16353f57c722b4e4b4 |
|
BLAKE2b-256 | ba2a84c2c649b14ab1d6c05e6094671af5fe89989beb1138a18eae1f10922f15 |