DEV Community

Kelvin Wangonya
Kelvin Wangonya

Posted on • Edited on • Originally published at wangonya.com

6

Publishing your Python packages on TestPyPi before publishing on PyPi

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 https://test.pypi.org/ and create one.

2. Update setup.py

We kept the setup.py 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("README.md", "r") as fh:
    long_description = fh.read()

setup(
        name="contacts",
        version="0.1.0",
        packages=find_packages(),
        description="Save contacts from your terminal",
        long_description=long_description,
        long_description_content_type="text/markdown",
        url="https://github.com/wangonya/contacts-cli",
        author="Kinyanjui Wangonya",
        author_email="kwangonya@gmail.com",
        license="MIT",
        classifiers=[
            "License :: OSI Approved :: MIT License",
            "Programming Language :: Python :: 3",
            "Programming Language :: Python :: 3.7",
        ],
        install_requires=[
            "Click",
            "requests",
            ],
        entry_points="""
        [console_scripts]
        contacts=app:cli
        """,
        )

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 setup.py sdist bdist_wheel
Enter fullscreen mode Exit fullscreen mode

This will generate a dist folder with the distribution packages:

dist/
├── 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 https://test.pypi.org/legacy/ dist/*
Enter your username:
Enter your password:
Uploading distributions to https://test.pypi.org/legacy/
Uploading contacts-0.1.0-py3-none-any.whl
100%|███████████████████████████████████████████████████████████|
Uploading contacts-0.1.0.tar.gz
100%|███████████████████████████████████████████████████████████|
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 https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple 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.

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay