Deploying a New Python Package to Pypi

Python is a great programming language. The main reason python is so popular is the growing number of packages available to anyone. You can find those packages in many websites and in package managers. The official package manager for python is pypi , there are 2 versions – one for testing and one for production

Lets go over the process:

  • Create the package
  • Test the package locally
  • Add it to git and github (optional)
  • Deploy the package to the test package manager
  • Test the package from pypitest
  • Deploy the package to pypi production
  • Test the package from pypi
  • Update package version and re-deploy it

 

Create a github repository:

 

To create a package add a new directory and create a file __init__.py (you can leave it empty or add some package initialization)

Add the following functions to strlib.py

update git and github:

test the module using python or ipython shell (in the root package directory)

Configure  pypi

Create accounts for the test site and the production site

Create a file for your pypi accounts. You should name it .pypirc (note the dot) and place it in your home directory (~)

~/.pypirc

 

Configure the Package For pypi

First we need to add 2 files to the root directory of the module:

setup.cfg:

And a setup script :

setup.py

Add tags and update github:

Deploy The Package to pypitest:

First make sure you have an updated version of setuptools and twine packages:

Now run this to deploy the package:

 

Testing The Package

To test the package , lets create a virtual environment :

 

Deploy The Package To Production

to deploy to pypi:

 

Using The Production Package

 

 

Creating a new version

Update your code

Add a new git tag and push changes

Update setup.py and change the version number

run setup.py:

deploy to pypi test and production

 

Now if you install the package again you will get version 0.2

 

 

Tagged

1 thought on “Deploying a New Python Package to Pypi

  1. […] How to deploy a new Python package to PyPI. […]

Leave a Reply

Your email address will not be published. Required fields are marked *