Publishing to pypi

Yesterday I published something to pypi for the first time in a while:

(it's a fake spotipy library for helping write python unit tests without having to actually call Spotify's API)


The Python Package Index (PyPI) is a repository of software for the Python programming language.

Currently, when you search Google for "publish to pypi", this is the top post:

but it contains some outdated/deprecated information. Much of the information is still useful, like writing your file, and registering for accounts on PyPI and PyPI Test, but when it comes to actually publishing, there are a few changes.

This tutorial is actually much better:


Here's the short version/my notes:


You'll need to create a file for your project. Here's the one I made yesterday:

2. Twine

You'll need this twine library to publish.

pip install twine

3. Source distribution

You have to create a source distribution:

python sdist

4. Wheel

It's good to create a wheel for your project, for faster end-user installation (faster than building from source).

For this you'll need wheel:

pip install wheel

There are three types of wheels, Universal, Pure Python, and Platform.

See the wheels section of the docs for further info on which type you need.

Mine was universal, so I did:

python bdist_wheel --universal

5. Uploading

The article talks about setting up a $HOME/.pypirc file so you don't have to enter your credentials everytime, but this seems insecure to me, so I skipped it.

To upload your source distribution (and potentially wheels) to Test PyPI:

twine upload --repository-url dist/*

And to go to real PyPI:

twine upload dist/*