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:
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.
.pypirc and put the contents shown below
.pypirc file contents
You should replace
YOUR_PASSWORD_HERE with your username and password from PyPI sites that you just created.
3: The Python Package directory structure
source_diris a root directory that contains your python package
my_python_packageis your main python package that you want to publish
Setup your directory structure as shown above, with appropriate changes, and host it on github.com.
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:
- Go to your project homepage on github
- On top, you will see Release link. Click on it.
- Click on Draft a new relase
- Fill in all the details
- Tag version should be the version number of your package release
- Release Title can be anything you want.
- Click Publish release at the bottom of the page
- Now under Releases you can view all of your releases.
- Copy the download link (tar.gz) and save it somewhere.
5: Editing files
Open the setup.py file and add following skeleton to it
Open the setup.cfg file and add following skeleton to it
Now push everything to github.
6: Publish the package
Execute following commands
This command will try to register your package on PyPI test server. This makesures that everything you have setup is correct.
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
Congratulations! You just published your python package on PyPI