Manipulate PyPI API tokens
PyPIToken is an open-source Python 3.7+ 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) # [NoopRestriction()] token.restrict(projects=["requests"]) print(token.restrictions) # [NoopRestriction(), ProjectsRestriction(projects=["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:
In the Python Packaging discussions for putting the project under the PyPA umbrella
In the Warehouse tracker for replacing the current macaroon implementation with this lib
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.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for pypitoken-5.0.0-py3-none-any.whl