How to Create Python Packages

Once we’ve written our code information, setup configuration, and examined the set up — we’re able to construct our bundle distribution.

The construct course of creates a brand new listing dist which is able to include a .tar.gz and .whl file — that is what we have to publish our bundle to PyPI.

To construct our dist information, we use a instrument creatively named construct. First, we pip set up construct, then, whereas in our bundle listing — sort:

python -m construct

Once that is full, we must always discover a new /dist listing inside our bundle listing.

Table of Contents

Publish to TestPyPI

Finally, we’re able to publish our new Python bundle! Again, we make use of one other bundle known as twine. We set up this with:

pip set up twine

Once put in, we add to TestPyPI — a ‘test’ model of PyPI in order that we will double-check that we have now set every part up accurately. We do that by typing:

python -m twine add --repository testpypi dist/*

At this level, we’ll have to login to TestPyPI — when you don’t have an account, join one here. If every part is about up accurately, our bundle might be uploaded:

Successful add course of for aesthetic_ascii on check PyPI

Now, we will check that our new bundle works by means of one other pip set up — however this time from TestPyPI:

pip set up -i aesthetic-ascii

(If you discover that the bundle is already put in — simply pip uninstall aesthetic-ascii).

Installing aesthetic-ascii through TestPyPI


Once we’ve confirmed that the bundle works — we take our ultimate step, publishing to PyPI. Again, you’ll have to register here.

Next, we add our bundle to PyPI with:

python -m twine add --repository pypi dist/*
Uploading our bundle to PyPI

And we’re achieved!


Please enter your comment!
Please enter your name here