Skip to main content

Platform-Agnostic Security Tokens for Python (PASETO)

Project description

PASETO Tokens for Python

PyPI PyPI - License CI

This is an unofficial implementation of PASETO: Platform-Agnostic Security Tokens for Python.

PASETO versions supported: v2, v3, and v4

Please note that the v2 token type standard is expected to be deprecated in 2022, so new development should be done ideally on versions 3 or 4.

Installation

pip install paseto

Usage

To create/parse paseto tokens, use the create/parse functions. These will automatically handle encoding/decoding the JSON payload for you, and validate claims (currently just the 'exp' expiration registered claim).

import paseto
from paseto.keys.symmetric_key import SymmetricKey
from paseto.protocols.v4 import ProtocolVersion4
my_key = SymmetricKey.generate(protocol=ProtocolVersion4)

# create a paseto token that expires in 5 minutes (300 seconds)
token = paseto.create(
    key=my_key,
    purpose='local',
    claims={'my claims': [1, 2, 3]},
    exp_seconds=300
)

parsed = paseto.parse(
    key=my_key,
    purpose='local',
    token=token,
)
print(parsed)
# {'message': {'exp': '2021-10-25T22:43:20-06:00', 'my claims': [1, 2, 3]}, 'footer': None}

You can also make and verify "public" tokens, which are signed but not encrypted:

import paseto
from paseto.keys.asymmetric_key import AsymmetricSecretKey
from paseto.protocols.v4 import ProtocolVersion4
my_key = AsymmetricSecretKey.generate(protocol=ProtocolVersion4)

# create a paseto token that expires in 5 minutes (300 seconds)
token = paseto.create(
    key=my_key,
    purpose='public',
    claims={'my claims': [1, 2, 3]},
    exp_seconds=300
)

parsed = paseto.parse(
    key=my_key,
    purpose='public',
    token=token,
)
print(parsed)
# {'message': {'exp': '2021-10-25T22:43:20-06:00', 'my claims': [1, 2, 3]}, 'footer': None}

Changelog

v2.0.0

  • Dropping support for python 3.7
  • Adding support for python 3.11 and 3.12
  • Dependency updates for pendulum, pysodium, pycryptodomex

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

paseto-2.0.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

paseto-2.0.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file paseto-2.0.0.tar.gz.

File metadata

  • Download URL: paseto-2.0.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for paseto-2.0.0.tar.gz
Algorithm Hash digest
SHA256 93d904b5f502ae662e651bc9b5142100bb3a3b986b5bafdf05454644d7f95421
MD5 54c3b074fcea5e7cb9fbe906f1387c15
BLAKE2b-256 678d9191b1e1d966f00e606c04239d6f7c8246fb1cb86c0498b15a667afdfaf2

See more details on using hashes here.

File details

Details for the file paseto-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: paseto-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for paseto-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 670651ef94fc7cd98ffa94e5893434e9f659ea57d1986bfe39f473efa5aaf1b1
MD5 d5ee47a90e16e55d56b5e51d379b5804
BLAKE2b-256 755f71716f91509873788678a752b6b47dd0c0e0cae6375205ce03d4d2c5390c

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