blob: 5f7b3bbc4f9174a4b8bab95b446a05cbb329d3c7 [file] [log] [blame]
Larry Hastings3732ed22014-03-15 21:13:56 -07001.. _distributing-index:
2
3###############################
4 Distributing Python Modules
5###############################
6
7:Email: distutils-sig@python.org
8
9
10As a popular open source development project, Python has an active
11supporting community of contributors and users that also make their software
12available for other Python developers to use under open source license terms.
13
14This allows Python users to share and collaborate effectively, benefiting
15from the solutions others have already created to common (and sometimes
16even rare!) problems, as well as potentially contributing their own
17solutions to the common pool.
18
19This guide covers the distribution part of the process. For a guide to
20installing other Python projects, refer to the
21:ref:`installation guide <installing-index>`.
22
23.. note::
24
25 For corporate and other institutional users, be aware that many
26 organisations have their own policies around using and contributing to
27 open source software. Please take such policies into account when making
28 use of the distribution and installation tools provided with Python.
29
30
31Key terms
32=========
33
Stéphane Wirtel19177fb2018-05-15 20:58:35 +020034* the `Python Packaging Index <https://pypi.org>`__ is a public
Larry Hastings3732ed22014-03-15 21:13:56 -070035 repository of open source licensed packages made available for use by
36 other Python users
37* the `Python Packaging Authority
Georg Brandl5d941342016-02-26 19:37:12 +010038 <https://www.pypa.io/>`__ are the group of
Larry Hastings3732ed22014-03-15 21:13:56 -070039 developers and documentation authors responsible for the maintenance and
40 evolution of the standard packaging tools and the associated metadata and
41 file format standards. They maintain a variety of tools, documentation
42 and issue trackers on both `GitHub <https://github.com/pypa>`__ and
Peter Bittnerd34ac302019-10-23 11:17:30 +020043 `Bitbucket <https://bitbucket.org/pypa/>`__.
Nick Coghlan3894ae22014-10-26 00:00:04 +100044* :mod:`distutils` is the original build and distribution system first added
45 to the Python standard library in 1998. While direct use of :mod:`distutils`
46 is being phased out, it still laid the foundation for the current packaging
Larry Hastings3732ed22014-03-15 21:13:56 -070047 and distribution infrastructure, and it not only remains part of the
48 standard library, but its name lives on in other ways (such as the name
49 of the mailing list used to coordinate Python packaging standards
50 development).
Nick Coghlan3894ae22014-10-26 00:00:04 +100051* `setuptools`_ is a (largely) drop-in replacement for :mod:`distutils` first
Zachary Ware66f305b2014-06-05 13:41:06 -050052 published in 2004. Its most notable addition over the unmodified
Nick Coghlan3894ae22014-10-26 00:00:04 +100053 :mod:`distutils` tools was the ability to declare dependencies on other
Nick Coghlane1d54e52014-05-26 00:50:11 +100054 packages. It is currently recommended as a more regularly updated
Nick Coghlan3894ae22014-10-26 00:00:04 +100055 alternative to :mod:`distutils` that offers consistent support for more
Nick Coghlane1d54e52014-05-26 00:50:11 +100056 recent packaging standards across a wide range of Python versions.
Nick Coghlan3894ae22014-10-26 00:00:04 +100057* `wheel`_ (in this context) is a project that adds the ``bdist_wheel``
58 command to :mod:`distutils`/`setuptools`_. This produces a cross platform
Nick Coghlane1d54e52014-05-26 00:50:11 +100059 binary packaging format (called "wheels" or "wheel files" and defined in
60 :pep:`427`) that allows Python libraries, even those including binary
61 extensions, to be installed on a system without needing to be built
62 locally.
Larry Hastings3732ed22014-03-15 21:13:56 -070063
Ned Deily8f5798e2016-06-05 17:38:48 -070064.. _setuptools: https://setuptools.readthedocs.io/en/latest/
Sanyam Khurana338cd832018-01-20 05:55:37 +053065.. _wheel: https://wheel.readthedocs.io/
Larry Hastings3732ed22014-03-15 21:13:56 -070066
67Open source licensing and collaboration
68=======================================
69
70In most parts of the world, software is automatically covered by copyright.
71This means that other developers require explicit permission to copy, use,
72modify and redistribute the software.
73
74Open source licensing is a way of explicitly granting such permission in a
75relatively consistent way, allowing developers to share and collaborate
76efficiently by making common solutions to various problems freely available.
77This leaves many developers free to spend more time focusing on the problems
78that are relatively unique to their specific situation.
79
80The distribution tools provided with Python are designed to make it
81reasonably straightforward for developers to make their own contributions
82back to that common pool of software if they choose to do so.
83
84The same distribution tools can also be used to distribute software within
85an organisation, regardless of whether that software is published as open
86source software or not.
87
88
89Installing the tools
90====================
91
92The standard library does not include build tools that support modern
93Python packaging standards, as the core development team has found that it
94is important to have standard tools that work consistently, even on older
95versions of Python.
96
97The currently recommended build and distribution tools can be installed
Nick Coghlan1d520962014-09-06 20:38:23 +100098by invoking the ``pip`` module at the command line::
Larry Hastings3732ed22014-03-15 21:13:56 -070099
Nick Coghlan1d520962014-09-06 20:38:23 +1000100 python -m pip install setuptools wheel twine
101
102.. note::
103
104 For POSIX users (including Mac OS X and Linux users), these instructions
105 assume the use of a :term:`virtual environment`.
106
107 For Windows users, these instructions assume that the option to
108 adjust the system PATH environment variable was selected when installing
109 Python.
Larry Hastings3732ed22014-03-15 21:13:56 -0700110
Nick Coghlane1d54e52014-05-26 00:50:11 +1000111The Python Packaging User Guide includes more details on the `currently
112recommended tools`_.
113
Sanyam Khurana338cd832018-01-20 05:55:37 +0530114.. _currently recommended tools: https://packaging.python.org/guides/tool-recommendations/#packaging-tool-recommendations
Larry Hastings3732ed22014-03-15 21:13:56 -0700115
Nick Coghlane7880572019-05-24 00:06:39 +1000116.. index::
117 single: Python Package Index (PyPI)
118 single: PyPI; (see Python Package Index (PyPI))
119
120.. _publishing-python-packages:
121
122Reading the Python Packaging User Guide
123=======================================
Larry Hastings3732ed22014-03-15 21:13:56 -0700124
125The Python Packaging User Guide covers the various key steps and elements
Nick Coghlane7880572019-05-24 00:06:39 +1000126involved in creating and publishing a project:
Larry Hastings3732ed22014-03-15 21:13:56 -0700127
128* `Project structure`_
129* `Building and packaging the project`_
Nick Coghlan5c4fbd52014-10-04 21:11:25 +1000130* `Uploading the project to the Python Packaging Index`_
Larry Hastings3732ed22014-03-15 21:13:56 -0700131
132.. _Project structure: \
Sanyam Khurana338cd832018-01-20 05:55:37 +0530133 https://packaging.python.org/tutorials/distributing-packages/
Larry Hastings3732ed22014-03-15 21:13:56 -0700134.. _Building and packaging the project: \
Sanyam Khurana338cd832018-01-20 05:55:37 +0530135 https://packaging.python.org/tutorials/distributing-packages/#packaging-your-project
Nick Coghlan5c4fbd52014-10-04 21:11:25 +1000136.. _Uploading the project to the Python Packaging Index: \
Sanyam Khurana338cd832018-01-20 05:55:37 +0530137 https://packaging.python.org/tutorials/distributing-packages/#uploading-your-project-to-pypi
Larry Hastings3732ed22014-03-15 21:13:56 -0700138
139
140How do I...?
141============
142
143These are quick answers or links for some common tasks.
144
145... choose a name for my project?
146---------------------------------
147
148This isn't an easy topic, but here are a few tips:
149
Nick Coghlan5c4fbd52014-10-04 21:11:25 +1000150* check the Python Packaging Index to see if the name is already in use
Peter Bittnerd34ac302019-10-23 11:17:30 +0200151* check popular hosting sites like GitHub, Bitbucket, etc to see if there
Larry Hastings3732ed22014-03-15 21:13:56 -0700152 is already a project with that name
153* check what comes up in a web search for the name you're considering
154* avoid particularly common words, especially ones with multiple meanings,
155 as they can make it difficult for users to find your software when
156 searching for it
157
158
159... create and distribute binary extensions?
160--------------------------------------------
161
162This is actually quite a complex topic, with a variety of alternatives
163available depending on exactly what you're aiming to achieve. See the
164Python Packaging User Guide for more information and recommendations.
165
166.. seealso::
167
168 `Python Packaging User Guide: Binary Extensions
Sanyam Khurana338cd832018-01-20 05:55:37 +0530169 <https://packaging.python.org/guides/packaging-binary-extensions/>`__
Larry Hastings3732ed22014-03-15 21:13:56 -0700170
171.. other topics:
172
173 Once the Development & Deployment part of PPUG is fleshed out, some of
174 those sections should be linked from new questions here (most notably,
175 we should have a question about avoiding depending on PyPI that links to
Georg Brandl5d941342016-02-26 19:37:12 +0100176 https://packaging.python.org/en/latest/mirrors/)