How to publish your own pip package

The Python Package Index, abbreviated as PyPI is the official third-party software repository for Python.

This is the primary way to install libraries in python. For example, if you want to use tensorflow package, just run the command pip install tensorflow and you will have it installed on your system.

Pip packages, in the most basic sense, are libraries or projects which can be downloaded to a location where all your python packages are stored locally. These can then be imported in your codes as and when required. So, when you run pip install tensorflow command, a copy of the tensorflow library is saved to your local system and you can access all of the codes and import any functions or classes via python.

Now, contrary to what many people might think, it is surprisingly easy to publish your own pip package. This guide will tell you exactly how.

Content for this article has been taken from the official pypi guide for creating pip packages which is available here:

Creating package files

First, make sure your project is sufficiently organised and uploaded to GitHub, complete with all the necessary functions to be used for the pip package.

Now, create a directory structure as follows:

|---> my_package
|---> <other package files>

Let’s look at each of these files one by one:

  1. my_project: The name of your git repository.
  2. LICENSE: It’s important for every package uploaded to the Python Package Index to include a license. This tells users who install your package the terms under which they can use your package. For help picking a license, see Once you have chosen a license, open LICENSE and enter the license text.
  3. Your readme file describing your project.
  4. my_package: The name of the package you want to publish. This directory should have all the codes files required for running your library. my_package/ is required to import the directory as a package, and can simply be an empty file.
  5. This is the build script for setuptools. It tells setuptools about your package (such as the name and version) as well as which code files to include.


Open and enter the following content:

import setuptools

with open("", "r", encoding="utf-8") as fh:
long_description =

name="my_package", # Replace with your own username
author="Example Author",
description="A small example package",
install_requires = ['tensorflow',
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",

setup() takes several arguments. The ones used here are described below:

  • name is the distribution name of your package.
  • version is the package version see PEP 440 for more details on versions.
  • author and author_email are used to identify the author of the package.
  • description is a short, one-sentence summary of the package.
  • long_description is a detailed description of the package. This is shown on the package detail page on the Python Package Index. In this case, the long description is loaded from which is a common pattern.
  • long_description_content_type tells the index what type of markup is used for the long description. In this case, it’s Markdown.
  • url is the URL for the homepage of the project. For many projects, this will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting service.
  • install_requires includes a list of all the dependencies which needs to be installed for the library to work.
  • packages is a list of all Python import packages that should be included in the Distribution Package. Instead of listing each package manually, we can use find_packages() to automatically discover all packages and subpackages. In this case, the list of packages will be my_package as that’s the only package present.
  • classifiers gives the index and pip some additional metadata about your package. In this case, the package is only compatible with Python 3, is licensed under the MIT license, and is OS-independent.
  • python_requires, as the name suggests, is the python version required for the library to work.

If you have completed the above steps, your basic code structure for publishing the package is complete.

Generating distribution archives

The next step is to generate distribution packages for the package. These are archives that are uploaded to the Package Index and can be installed by pip.

Make sure you have the latest versions of setuptools and wheel installed:

pip install setuptools wheel

Now run this command from the same directory where is located:

python sdist bdist_wheel

This command should output a lot of text and once completed should generate two files in the dist directory:


Uploading your package to the Python Package Index!

The first thing you’ll need to do is register an account on PyPI. To register an account, go to this and complete the steps on the page.

Now you’ll create a PyPI API token so you will be able to securely upload your project. Click here and create a new API token.

Now that you are registered, you can use twine to upload the distribution packages. You’ll need to install Twine:

pip install twine

Once installed, run Twine to upload all of the archives under dist:

python -m twine upload dist/*

You will be prompted for a username and password. For the username, use __token__. For the password, use the token value, including the pypi- prefix.

After the command completes, you should see output similar to this:

Uploading distributions to
Enter your username: [your username]
Enter your password:
Uploading my_package-0.0.1-py3-none-any.whl
100%|█████████████████████| 4.65k/4.65k [00:01<00:00, 2.88kB/s]
Uploading my_package-0.0.1.tar.gz
100%|█████████████████████| 4.25k/4.25k [00:01<00:00, 3.05kB/s]

Once uploaded your package should be viewable on PyPI, for example,

If you have successfully followed the above process, congratulations, you have published your own pip package.

Finally, install your package from the real PyPI using pip install [my_package].

I have created my own package using the same method:

The pip package homepage looks like this:

Project details for the same can be found at:

My article for the above project is available on medium at:

Thank you for reading the article, suggestions for improvement are welcome in comments.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store