Skip to main content

Platform-Agnostic Security Tokens for Python

Project description

python-paseto

Platform-Agnostic Security Tokens for Python

Build Status test-workflow PyPI version Coverage Status Language grade: Python Code style: black

Installation

pip install python-paseto

Check installation

python -m paseto

libsodium is required, this will check if it is installed on your system. On Ubuntu 20.04 you can get it with sudo apt install libsodium23.

Low level API

Implements PASETO Version2 and Version4 protocols supporting v2.public, v2.local, v4.public and v4.local messages. Every protocol version provides access to encrypt() / decrypt() and sign() / verify() functions.

Low level API is focuses on solid, high quality, production ready primitives as specified directly in the PASETO protocol. See paseto-spec for protocol details.

Example use with Version2

from paseto.protocol.version2 import encrypt, decrypt

message = b"foo"  # your data
key = b"0" * 32  # encryption key

token = encrypt(message, key)
plain_text = decrypt(token, key)

assert plain_text == message
print(f"token={token}")
print(f"plain_text={plain_text}")
print(f"message={message}")

With optional footer

from paseto.protocol.version2 import encrypt, decrypt

message = b"foo"  # your data
key = b"0" * 32  # encryption key
optional_footer = b"sample_footer"  # authenticated but not encrypted metadata

token = encrypt(message, key, optional_footer)
plain_text = decrypt(token, key, optional_footer)

assert plain_text == message
print(f"token={token}")
print(f"plain_text={plain_text}")
print(f"message={message}")

Example use with Version4

from paseto.protocol.version4 import create_symmetric_key, decrypt, encrypt

message = b"this is a secret message"  # your data
key = create_symmetric_key()  # encryption key

token = encrypt(message, key)
plain_text = decrypt(token, key)

assert plain_text == message
print(f"token={token}")
print(f"plain_text={plain_text}")
print(f"message={message}")

Message signing

from paseto.protocol.version4 import create_asymmetric_key, sign, verify

message = b"this is a public message"  # your data
public_key, secret_key = create_asymmetric_key()  # signing / verifying keys

token = sign(message, secret_key)
verified_message = verify(token, public_key)

assert verified_message == message
print(f"token={token}")
print(f"verified_message={verified_message}")
print(f"message={message}")

High level API

In the future a high level API will provide developer friendly access to low level API and support easy integration into other projects.

Development

Typical dev workflow operations are automated in Makefile, including testing, linting, code quality checks, benchmarks and dev environment setup.

Contributing

This library is under active development and maintenance. For any feedback, questions, comments or if you would like to request a feature, please raise an issue!

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

python-paseto-0.5.2a0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

python_paseto-0.5.2a0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file python-paseto-0.5.2a0.tar.gz.

File metadata

  • Download URL: python-paseto-0.5.2a0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.7 Linux/5.8.0-1042-azure

File hashes

Hashes for python-paseto-0.5.2a0.tar.gz
Algorithm Hash digest
SHA256 7cac1a87ba8477227e13a0bbeeaaf4d1d3633b450d8bc024d553865c23552183
MD5 dc8c903fac9a497ff10d3fccfc054d03
BLAKE2b-256 15529f5844a76499a6f3abeb2a66ca53d4eb00a61f2f7613c274c174208bbd57

See more details on using hashes here.

File details

Details for the file python_paseto-0.5.2a0-py3-none-any.whl.

File metadata

  • Download URL: python_paseto-0.5.2a0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.7 Linux/5.8.0-1042-azure

File hashes

Hashes for python_paseto-0.5.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 d33310ef086bb327c0362d38ead83f79ac10cfd4435c315628b692bb9758af5d
MD5 c62aaf5defca990e9f6d3a99f2e7e56f
BLAKE2b-256 c02da93ac6dc7bd2f70a18916a8b90378c251fa7677a0f50d12533ada228cd2e

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