Publish python package on PyPI

PyPI is the official Python Packages Index. Once you publish it on PyPI then it will can downloaded via a simple command pip install <package>. Life becomes simpler with this one line installation.

1: Create accounts

In order to submit your package on PyPI you need to have few accounts on PyPI websites. These account will enable you to maintain your packages and will provide you with an interface to edit your package.

Create your account on following sites:

2: The .pypirc file

Now create a file in your home folder named .pypirc, which will be your configuration file that holds the authentication information of your PyPI accounts.

Create file .pypirc and put the contents shown below

vim ~/.pypirc

.pypirc file contents

index-servers =



You should replace YOUR_USERNAME_HERE and YOUR_PASSWORD_HERE with your username and password from PyPI sites that you just created.

3: The Python Package directory structure

  • source_dir is a root directory that contains your python package
  • my_python_package is your main python package that you want to publish
source_dir/                 # the source directory
|-- my_python_package       # your package
|   |--
|   `-- FILES ....          # your package files
|-- setup.cfg

Setup your directory structure as shown above, with appropriate changes, and host it on

4: Release on github and get the download link

This step involves releasing your package on github. This will create a download link of your complete source. In order to release your github project, you need to carry on following steps:

  1. Go to your project homepage on github
  2. On top, you will see Release link. Click on it.
  3. Click on Draft a new relase
  4. Fill in all the details
    • Tag version should be the version number of your package release
    • Release Title can be anything you want.
  5. Click Publish release at the bottom of the page
  6. Now under Releases you can view all of your releases.
  7. Copy the download link (tar.gz) and save it somewhere.

5: Editing files

Open the file and add following skeleton to it

from distutils.core import setup

    name = 'my_python_package',
    packages = ['my_python_package'],
    version = 'version number',  # Ideally should be same as your github release tag varsion
    description = 'description',
    author = '',
    author_email = '',
    url = 'github package source url',
    download_url = 'download link you saved',
    keywords = ['tag1', 'tag2'],
    classifiers = [],

Open the setup.cfg file and add following skeleton to it

description-file =

Now push everything to github.

6: Publish the package

Execute following commands

python register -r pypitest

This command will try to register your package on PyPI test server. This makesures that everything you have setup is correct.

python sdist upload -r pypitest

This command will upload your package on test repository and now you should see your package on PyPI Test

Now you are ready to publish your package on PyPI Live Server. Execute following commands

python register -r pypi
python sdist upload -r pypi

Congratulations! You just published your python package on PyPI


  1. Official Documentation

Arpit Bhayani

Arpit's Newsletter

CS newsletter for the curious engineers

❤️ by 38000+ readers

If you like what you read subscribe you can always subscribe to my newsletter and get the post delivered straight to your inbox. I write essays on various engineering topics and share it through my weekly newsletter.

Other essays that you might like

Set Similarity using Jaccard Similarity Coefficient and MinHash

1481 reads 2020-11-08

Set similarity measure finds its application spanning the Computer Science spectrum; some applications being - user segm...

Personalize your Python Prompt

1763 reads 2020-02-21

Personalization is what we all love. In this article we find how we could personalize the Python interpreter prompt >>>...

Pseudorandom Number Generation using Cellular Automata - Rule 30

1011 reads 2020-02-14

Generating pseudorandom numbers is an interesting problem in Computer Science. In this article, we dive deep into an alg...

Stop an Iterating Loop

426 reads 2019-09-06

There are two ways through which we can stop an iterating loop, first by using break statement and second by making loop...

Be a better engineer

A set of courses designed to make you a better engineer and excel at your career; no-fluff, pure engineering.

Paid Courses

System Design for Beginners

A masterclass that helps early engineers and product managers become great at designing scalable systems.

180+ learners

Details →

System Design Masterclass

A masterclass that helps you become great at designing scalable, fault-tolerant, and highly available systems.

1000+ learners

Details →

Redis Internals

Learn internals of Redis by re-implementing some of the core features in Golang.

98+ learners

Details →

Free Courses

Designing Microservices

A free playlist to help you understand Microservices and their high-level patterns in depth.

823+ learners

Details →

GitHub Outage Dissections

A free playlist to help you learn core engineering from outages that happened at GitHub.

651+ learners

Details →

Hash Table Internals

A free playlist to help you understand the internal workings and construction of Hash Tables.

1027+ learners

Details →

BitTorrent Internals

A free playlist to help you understand the algorithms and strategies that power P2P networks and BitTorrent.

692+ learners

Details →