Today I learned how to publish a Python package to PyPI with uv.
Publishing a package to PyPI with uv was quite simple. All I had to do was read the documentation with the steps provided and I was done in less than 2 minutes.
The package I'm publishing is my CLI that solves the LinkedIn Queens puzzle, about which I wrote in a different article.
The first thing I did was make sure I could build my package with
uv build
The next step is to run uv publish
.
To publish a package to PyPI I needed a token for authentication.
To get that, I opened my account settings, scrolled to “API tokens”, and created a new token that was scoped to “all projects” because the project I want to upload/publish hasn't been created yet.
After I created that token, I ran
uv publish --token MY_TOKEN_HERE
That took a second to run and then my project li_queens
was published on PyPI.
Now that the project exists, I went to my PyPI account settings, deleted the generic API token I created just now, and then I created a token that's scoped specifically for the project li_queens
.
Now that the package is published, you can use uv
to run my CLI queens
without even having to install the package explicitly.
If puzzle.png
is an image with a LinkedIn Queens-like puzzle, just run
uvx --from li_queens queens puzzle.png
This was done with uv 0.6.1. Make sure to use an updated version of uv and check the uv documentation on publishing packages for the most current instructions and notes on caveats to be aware of.
+35 chapters. +400 pages. Hundreds of examples. Over 30,000 readers!
My book “Pydon'ts” teaches you how to write elegant, expressive, and Pythonic code, to help you become a better developer. >>> Download it here 🐍🚀.