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.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file pytokenx-0.0.2.tar.gz.

File metadata

  • Download URL: pytokenx-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 1fc79caceb7c935dc979ec6005ee54e25643cdf811ee461e497f528c5b1d47fb
MD5 8125550253c8d6426125c0b7b3cc2c7e
BLAKE2b-256 6f35fb57ea1fe2d2dd3739d0acfe26fd860af7a81b28913360a5c33a47d67c11

See more details on using hashes here.

File details

Details for the file pytokenx-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pytokenx-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 170f90ea7b8b311ca1f1702ccc991fb8035a44b2db89343a4f65ea651cb40af3
MD5 e223862da89650955cb3895678d88234
BLAKE2b-256 5b0ce23b27fec8ba46d0e782f49228070f303845fbb8970222a9e4569e6dbd70

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