Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Uploading Your Python Package to PyPI

Finally, this video shows you how to publish your Python package to PyPI. Furthermore, additional information about PyPI and packages are given. You can copy and paste the command from below (make sure to execute the command in your projects root directory).

Python
python -m twine upload dist/*

00:00 All right! Here we are—the main reason you’re watching this series. You’re now going to learn how to upload your project to the main PyPI site so that it’s available for all the world to see.

00:12 You’re not actually going to want to do this if you’re using the reader project that we’ve been working on, as it would add unnecessary clutter to the PyPI index.

00:21 If you have your own project that you want to upload, however, this is the command that you’ll use to send it off for everyone to see.

00:29 Just go python -m twine upload dist/*. If you go ahead and run that, you’ll be asked for your username and password, and that’s literally all you have to do.

00:44 You’ll see it pop up on the new releases page on PyPI, and you’ll be able to click on your profile to see your project. An example view of this would be, like, if I go to my account, I should be able to look at my projects, and I’ll see a project here that I started.

00:59 This is a pretty simple project that I started to work with Pandas, and I decided to use PyPI to make it easier to send to my colleagues. Speaking of distribution, that’s probably one of the best reasons for using PyPI.

01:12 Once you have your project up there, it gets added to the index used by pip. So if you wanted to say pip install xl-formulas,

01:28 I could then just go ahead and install that into any environment that I’m working in. You’ve probably already done it, but for the realpython-reader, we just went pip install realpython-reader.

01:44 So hopefully that’s not a little anti-climatic, but you can see that once you do all the groundwork for setting up your project, it’s really not that hard to get it out for the world. So, congratulations.

01:55 Now that you know how to structure a package and get it uploaded to PyPI, your next steps are to find some project that you would like to share with the world.

02:02 Python is such a powerful language because of all the open-source tools that are freely available to use. With a simple pip command, you can access the entirety of what PyPI has to offer.

02:14 In the next video, we’ll talk about a couple tools you can use to make packaging up projects a little bit easier, so check it out if you’re looking to improve your workflow.

02:22 Thanks for watching.

Martin Breuss RP Team on June 19, 2019

Updating your package

If you change something in your code, you’ll have to run the build tools again:

$ python3 setup.py sdist bdist_wheel
$ twine upload dist/*

You might run into the following error:

HTTPError: 400 Client Error: File already exists. See https://pypi.org/help/#file-name-reuse for url: https://upload.pypi.org/legacy/

If that happens to you, check up on 2 things:

  1. Make sure you updated the version number in both files
  2. Delete the old version files from your dist/ directory

Try again - you should be able to upload now! :)

Lee Jordan on Oct. 25, 2020

I found I had to just use my PYPI username and password instead of the API token and special token password. It did not like the token password no matter what I did.

Become a Member to join the conversation.