Published on 10th Nov 2015
2 min read
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.
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
[distutils] index-servers = pypi pypitest [pypi] repository: https://pypi.python.org/pypi username: YOUR_USERNAME_HERE password: YOUR_PASSWORD_HERE [pypitest] repository: https://testpypi.python.org/pypi username: YOUR_USERNAME_HERE password: YOUR_PASSWORD_HERE
You should replace
YOUR_PASSWORD_HERE with your username and password from PyPI sites that you just created.
source_diris a root directory that contains your python package
my_python_packageis your main python package that you want to publish
source_dir/|-- my_python_package | |-- __init__.py | `-- FILES .... |-- README.md |-- setup.cfg |-- setup.py
Setup your directory structure as shown above, with appropriate changes, and host it on github.com.
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:
Open the setup.py file and add following skeleton to it
from distutils.core import setup 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
[metadata] description-file = README.md
Now push everything to github.
Execute following commands
python setup.py 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 setup.py 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 setup.py register -r pypi
python setup.py sdist upload -r pypi
Congratulations! You just published your python package on PyPI