Publishing a Package to PyPI

To publish your library on https://pypi.org:

  1. Add the required metadata files.
  2. Build source and wheel distributions.
  3. Upload with twine.

Required files

setup.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from setuptools import setup, find_packages

setup(
name='sampleproject',
version='1.2.0',
description='A sample Python project',
py_modules=["my_module"],
# packages=find_packages(exclude=['contrib', 'docs', 'tests']),

long_description="",
url='https://github.com/pypa/sampleproject',
author='The Python Packaging Authority',
author_email='[email protected]',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
keywords='sample setuptools development',
install_requires=['peppercorn'],
extras_require={
'dev': ['check-manifest'],
'test': ['coverage'],
},
package_data={'sample': ['package_data.dat']},
data_files=[('my_data', ['data/data_file'])],
entry_points={
'console_scripts': ['sample=sample:main'],
},
project_urls={
'Bug Reports': 'https://github.com/pypa/sampleproject/issues',
'Funding': 'https://donate.pypi.org',
'Say Thanks!': 'http://saythanks.io/to/example',
'Source': 'https://github.com/pypa/sampleproject/',
},
)

README

Provide usage instructions in Markdown or reStructuredText.

LICENSE

Pick an open-source license; https://choosealicense.com/ helps if you are unsure.

Optional helpers include MANIFEST.in and setup.cfg for finer control.

Build the distributions

1
2
3
pip install wheel
python setup.py sdist
python setup.py bdist_wheel --universal # pure Python wheel for both 2 and 3

Upload

  1. Register: https://pypi.org/account/register/
  2. Install twine: pip install twine
  3. Upload: twine upload dist/*

Reference:

Packaging and Distributing Projects