DEV Community


Publishing your Python packages on TestPyPi before publishing on PyPi

Kinyanjui Wangonya
Originally published at Updated on ・2 min read

If you're just creating a package for learning purposes, there's no need (IMO) to pollute the official PyPi index with it. Also, you may want to release a package to a select number of users for testing before you actually release it officially. For these purposes, you're better off using TestPyPi:

a separate instance of the Python Package Index that allows you to try distribution tools and processes without affecting the real index.

Uploading to TestPyPi

For the final part of this series, I'll upload the app we created on TestPyPi. Here are the steps to follow:

1. Create an account on TestPyPi

You'll need an account to continue so head over to and create one.

2. Update

We kept the file very simple during development. Now we'll need to add some details to make it ready for publishing.

from setuptools import setup, find_packages

with open("", "r") as fh:
    long_description =

        description="Save contacts from your terminal",
        author="Kinyanjui Wangonya",
            "License :: OSI Approved :: MIT License",
            "Programming Language :: Python :: 3",
            "Programming Language :: Python :: 3.7",

Enter fullscreen mode Exit fullscreen mode

Most of the options are self-explanatory, but you can check what each of them means in the setup docs.

3. Build your package

In the root directory, run:

(env) $ python sdist bdist_wheel
Enter fullscreen mode Exit fullscreen mode

This will generate a dist folder with the distribution packages:

├── contacts-0.1.0-py3-none-any.whl
└── contacts-0.1.0.tar.gz
Enter fullscreen mode Exit fullscreen mode

4. Upload your package with twine

Install twine:

$ pip install twine
Enter fullscreen mode Exit fullscreen mode

Upload your package:

$ twine upload --repository-url dist/*
Enter your username:
Enter your password:
Uploading distributions to
Uploading contacts-0.1.0-py3-none-any.whl
Uploading contacts-0.1.0.tar.gz
Enter fullscreen mode Exit fullscreen mode

The package should now be uploaded on your account:

TestPyPi projects

To install the package locally from TestPyPi, run:

$ pip install --index-url --extra-index-url your-package
Enter fullscreen mode Exit fullscreen mode

--index-url tells pip to get the package from TestPyPi. If the package needs other dependencies to run, --extra-index-url has to be included so the dependencies can be fetched from the PyPi.

Discussion (0)