Skip to main content

Manipulate PyPI API tokens

Project description

Deployed to PyPI Deployed to PyPI GitHub Repository Continuous Integration Documentation Coverage MIT License Contributor Covenant

PyPIToken is an open-source Python 3.8+ library for generating and manipulating PyPI tokens.

PyPI tokens are very powerful, as that they are based on Macaroons. They allow the bearer to add additional restrictions to an existing token. For example, given a PyPI token that can upload releases for any project of its owner, you can generate a token that will only allow some projects, or even a single one.

Here’s an example:

$ pip install pypitoken
import pypitoken

token = pypitoken.Token.load("pypi-foobartoken")

print(token.restrictions)
# [ProjectIDsRestriction(project_ids=["00000000-0000-0000-0000-000000000000"])]

token.restrict(project_names=["requests"])

print(token.restrictions)
# [
#     ProjectIDsRestriction(project_ids=["00000000-0000-0000-0000-000000000000"]),
#     ProjectNamesRestriction(project_names=["requests"]),
# ]

token.dump()
# pypi-newfoobartoken

This token we’ve created above will be restricted to uploading releases of requests. Of course, your PyPI user will still need to have upload permissions on requests for this to happen.

The aim of this library is to provide a simple toolbelt for manipulating PyPI tokens. Ideally, someday, PyPI (Warehouse) itself may generate their tokens using this library too. This should make it easier to iterate on new kinds of restrictions for PyPI tokens, such as those discussed in the original implementation issue.

A discussion for integrating this library to the Warehouse environment is ongoing:

Where to go from here

The complete docs is probably the best place to learn about the project.

If you encounter a bug, or want to get in touch, you’re always welcome to open a ticket.

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

pypitoken-7.0.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

pypitoken-7.0.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file pypitoken-7.0.1.tar.gz.

File metadata

  • Download URL: pypitoken-7.0.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/6.2.0-1015-azure

File hashes

Hashes for pypitoken-7.0.1.tar.gz
Algorithm Hash digest
SHA256 dd90c8c1abb792b1de7f8380dccbaea238a1bd80e2231be8f5c527ed5ae510a2
MD5 383b951b4398ddba508cf4059e711093
BLAKE2b-256 df540fa3df5aeee2963b68b8a04b3fcbade5e96f9e00bc438f52f051fac0009c

See more details on using hashes here.

File details

Details for the file pypitoken-7.0.1-py3-none-any.whl.

File metadata

  • Download URL: pypitoken-7.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/6.2.0-1015-azure

File hashes

Hashes for pypitoken-7.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2966cc4c6f2ef9edeaa3a3e49febf748ff561c7acbdba911845998b2a6c8e16
MD5 40bf13b1feee2f5c5f93b28db0838d24
BLAKE2b-256 1634fc74ef1dd5b5e87681d7641d3c28911523ca99d164cf93343c6df27d7204

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