Skip to main content

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)

Uploaded Source

Built Distribution

pytokenx-0.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

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

Hashes for pytokenx-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a1d8dc21f98854815ff88f405268e43675542163245822f5910eebaa3952fa18
MD5 1444274b803ce27da2d9a8f8cdf779ce
BLAKE2b-256 0b70481ccb9f454c31b225509ecb9f6b0d033c00e33d06838daae9482efb297e

See more details on using hashes here.

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

Hashes for pytokenx-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a24dec4cfd0fdd8ba30e55a8ae431bf2c506cc787fc3e438b72fc79a103bd656
MD5 909a209018ad491c5285b3b8f528d3a6
BLAKE2b-256 e9d08baa2e5ebd470b3e422adf599d7b259c724033c3361711ce35b169941b64

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page