Registering and uploading python package to pip

Packaging and distributing in python is a bit difficult. PyPI, the python package index is the most common one. I will explain step by step, how to upload your package to PyPI.

Setup file

The first thing is to create a file in the root of your project.

from setuptools import setup

    name = "project",
    version = "0.1.0",
    author = "author name",
    author_email = "",
    description = ("Description of the package"),
    license = "MIT",
    keywords = "keywords",
    url = "http://url-of-project/",
    packages = ['packages'],
    long_description = "Provide a detailed explanation of your "\
                       "project and how it can be used",
    install_requires = [
    entry_points = {
        'console_scripts': [

This is a template for Just fill in your information like name, email, project description etc. Mention all your project dependencies in install_requires section. You also have to provide the entry_point for your program. You can do that with entry_points section.

project=project.main project is the name of the binary. Project in project.main is the package name and main is the name of the function to be called. So this will be the first function, that python calls.

Test the package locally

Once you are done with setup, we can generate the distributable file.

$ python sdist

This command generates the distributable zip file inside dist/ directory.

Extract the zip file, that is present in dist directory and cd into it.

$ python install

This command installs your package locally. You can do this to verify if your setup is correct or not. If is correct then the local install works fine.

Register with PyPI

To upload packages to PyPI, you have to be registered with them. Its simple, you can do it from the command line itself. Run the below command.

$ python register

Here you can register as a new user. Provide your username, email and password and you’re done. In this step, you will register yourself and not the package.

Next step is to register your package.

$ python register

This time, choose login as existing user. If you get Server response (200): OK, then your project is registered succesfully. Sometimes you might get the below error.

Registering lookup to Server response (403): You are not allowed to store 'project' package information

Check if there is any existing project in PyPI with the same name as your project. If yes, then you have to rename your project. After making the necessary changes register again (Run the command again).


Before running the upload command, you have to create ~/.pypirc file

Contents of .pypirc

password:password<Plain text>

After creating the file, run the following command

$ python sdist upload

This will generate the distributable and uploads it to PyPI. If everything goes well you will see Server response (200): OK on your terminal.

You have successfully uploaded your package to PyPI. Next time you can skip the user registration. No need to register again, you can use your existing credentials.