Before publishing your newly created Python package to PyPI it’s a good idea to test if everything is setup correctly. In this video you’ll double check whether everything is setup as expected and publish your package to the Test PyPI page.
Testing Your Python Package
Before you attempt an upload, you should make sure that everything you expect to be included in your package is actually there. If you’re on a Linux or Mac, you can run the following command to look inside the
tar file to double-check what’s present. So, change directory to that
dist/ folder, and you should—if you list everything in there—see your
tar and your wheel file.
And you can go ahead and type in
tar tzf and then the name, which in this case, the
tar has the dash (
-), and run that. And if I bring this up, you’ll see—well, the font size is a little hard to read, but everything should be in here. You’ve got your manifest, your
and then inside
config.txt. It looks like everything’s included. If you’re on Windows, you may need to download something like 7-zip to look in these types of files. But then I also have—in my text editor, if I bring this back down, I can actually just click on these and my text editor will open them up like it’s a file explorer.
01:07 So, this is a great quick way to make sure that everything’s laid out rather than looking at terminal output. A good quick check is also to use Twine, which is the tool that you’ll use to actually upload to PyPI.
And once you have that, you may be able to run
twine check and then just do—or actually, before we run this, let’s get back out into that main directory so that you can see the actual
dist/ folder. And try running
check dist/*, like that. Now, if you get an error after you’ve installed it saying
command not found, that just means that
pip decided to install
twine and not add it to your path variable. If you don’t want to add it to your path variable, you can also just say
python -m twine, and it’s just like the same thing.
So let’s just do
check dist/*. And of course, it’s not going to find that file because you need an asterisk (
*). Okay, cool. So, you should see that each of the files in there—it passed. This won’t catch everything, but it’ll make sure you’ve got all your formats correct, and that it should render properly on PyPI.
03:06 The only real difference is you have this banner up here that lets you know that you’re on the test site. So if you don’t have an account here, go ahead and click Register and create your account.
You should be able to call, well, in my case,
python -m twine, and then just say
upload. You’re going to add in another argument called
--repository-url, and this is how you define that you want to go to the test site, so just
https://test.pypi.org/legacy/, and then you want to send everything in that
dist/ folder, so
and look at that! Right down here in New releases, there’s the package I just uploaded. We can open this up, if you wanted to install it just like it was, you could go
pip install and use this separate URL.
05:01 It lists me as a maintainer. It’s got the License, the Author as Real Python, and the classifiers that were included. So, this is pretty cool! And everything looks right, so I think you’re ready in the next video to go ahead and upload your project to the real PyPI. It’s a pretty big step to take and it’s really exciting.
Become a Member to join the conversation.