How to submit you python package to PyPI

What is PyPi?

PyPI — the Python Package Index The Python Package Index is a repository of software for the Python programming language.

IF you are written something cool or simple app , and want to share it with other such a way that it can be easily installed by them. Then put your code in PyPi and then they can install you package simply by

pip install your-package  

STEPS :

Create Accounts :
  • Register at PyPI Live and also PyPI Test.
  • It will be easier if you use same credentials for both account.
  • If you have registered via OpenId or Google , remember to set the password after registration from the profile.

Create .pypirc config File
  • Create a .pypirc file in you home folder.

touch ~/.pypirc - Put bellow content on it,

  • Replace your_username and your_password with your pypi username and password.

Prepare Your Package
    app-root
        setup.py
        setup.cfg
        LICENSE.txt
        README.md
        docs
        tests
        CONTRIBUTORS
        .gitignore
        your_pacakge/
            __init__.py
            model.py
            lib.py
            ...

Now here is detail point of what you need,

  • Your package source will be on your_package directory.
  • docs folder will contain the documenation soruce for your package. You can make documentation with SPHINX and host it one READTHEDOCS
  • tests will contain the tests for your application
  • README.md will contain the repository description in MARKDOWN format.
  • setup.py will contain the following settings,

    Add a .gitignore file with following contents

    *.pyc
    .DS_Store
    *.egg
    *.egg-info
    dist
    /.idea
    _build
    

    Create a git tag

    git tag 0.1 -m "tags for first release"
    git push --tags origin master
    

    This will give you the download_url in setup.py. Format is https://github.com/{username}/{module_name}/tarball/{tag}

    • setup.cfg will contain the location of README file,

      [metadata]
      description-file = README.md
      

Upload Your Package/ Release an update
  • PyPI TEST

    python setup.py register -r pypitest
    python setup.py sdist upload -r pypitest
    
  • PyPI LIVE

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

You can check your package in PyPI Live and also PyPI Test.

N.B :

  • After uploading to test verify the content before uploading to live. You have to increase the version number each time you upload your package to PyPI.

References :
https://wiki.python.org/moin/CheeseShopTutorial#SubmittingPackagestothePackage_Index
http://peterdowns.com/posts/first-time-with-pypi.html