Publish Library in PyPI

Often there is a need for Python developers to upload their work (code) in Python’s huge repository -PyPI. I had run into the same problem. But somehow, after some tweaking I was able to complete this simple but tricky task.

  1. Create a repository in Github to host the source code.
  2. Sign up for an account in PyPI — https://pypi.python.org/pypi?%3Aaction=register_form

3. Create a .pypirc config file with the following contents in home directory (~/.pypirc)

[distutils]
index-servers =
pypi

[pypi]
repository=https://pypi.python.org/pypi
username=username
password=password

4. Change its permission so that only you can read/write it.

chmod 600 ~/.pypirc

5. To publish your code in PyPI, you ill need these three files in the root directory of your project

README.md : Mark down readme file.

LICENSE.txt : Describe your license.

setup.cfg and

[metadata]
description-file = README.md

setup.py

from distutils.core import setup
setup(
name='package_name',
packages=['package_name'],
version='1.0',
description='Package description',
author='Your Name',
author_email='author@emailprovider.com',
url='https://github.com/author/package_name',
download_url= 'https://github.com/author/repo/tarball/1.0',
keywords = ['tag1', 'tag2'],
classifiers = [],
)

6. Commit the recent files and create a TAG. The tag will create a direct download link of your repository with the version. e.g. https://github.com/author/repo/tarball/1.0

git add -A
git commit -m “Project now compatible for deployment in PyPI”
git tag 1.0 -m “Add tag for version 1.0”
git push origin master
git push — tags origin master

7. Final Step : Deploy in PyPI

python setup.py register -r pypi
python setup.py sdist upload -r pypi

You should receive a response something similar to this

Response : 200 OK

Congrats, you have published your code in PyPI. It can be installed by pip

pip install package_name