Skip to content

Instantly share code, notes, and snippets.

@davydany
Created June 24, 2017 01:14
Show Gist options
  • Save davydany/b08acef08f75fe297e13ae4d24ce9f4d to your computer and use it in GitHub Desktop.
Save davydany/b08acef08f75fe297e13ae4d24ce9f4d to your computer and use it in GitHub Desktop.
Uploading to PyPi

How to Upload to PyPi

Source: http://peterdowns.com/posts/first-time-with-pypi.html

I am writing this because the site is down and I'm only able to get it from Google Cache.

Create Your PyPiRC file

Create a new file in ~/.pypirc, and populate it with the following details:

[distutils]
index-servers =
  pypi
  pypitest

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

Now, set up the right permissions

$ chmod 600 ~/.pypirc

Setup your project

Ensure that your project follows a similar project structure:

root-dir/   # arbitrary working directory name
  setup.py
  setup.cfg
  LICENSE.txt
  README.md
  mypackage/
    __init__.py
    foo.py
    bar.py
    baz.py

And your setup.py is setup as such:

from distutils.core import setup
setup(
  name = 'mypackage',
  packages = ['mypackage'], # this must be the same as the name above
  version = '0.1',
  description = 'A random test lib',
  author = 'Peter Downs',
  author_email = '[email protected]',
  url = 'https://github.com/peterldowns/mypackage', # use the URL to the github repo
  download_url = 'https://github.com/peterldowns/mypackage/archive/0.1.tar.gz', # I'll explain this in a second
  keywords = ['testing', 'logging', 'example'], # arbitrary keywords
  classifiers = [],
)

Ensure you have a setup.cfg

[metadata]
description-file = README.md

Make sure you have a LICENSE.txt.

Publish it!

Let's do it for the PyPI Test environment

First you will need to register it:

python setup.py register -r pypitest

Now, upload it:

python setup.py sdist upload -r pypitest

Let's do it for the PyPI Live environment

First you will need to register it:

python setup.py register -r pypi

Now, upload it:

python setup.py sdist upload -r pypi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment