17db96d56Sopenharmony_ci.. _distributing-index:
27db96d56Sopenharmony_ci
37db96d56Sopenharmony_ci###############################
47db96d56Sopenharmony_ci  Distributing Python Modules
57db96d56Sopenharmony_ci###############################
67db96d56Sopenharmony_ci
77db96d56Sopenharmony_ci:Email: distutils-sig@python.org
87db96d56Sopenharmony_ci
97db96d56Sopenharmony_ci
107db96d56Sopenharmony_ciAs a popular open source development project, Python has an active
117db96d56Sopenharmony_cisupporting community of contributors and users that also make their software
127db96d56Sopenharmony_ciavailable for other Python developers to use under open source license terms.
137db96d56Sopenharmony_ci
147db96d56Sopenharmony_ciThis allows Python users to share and collaborate effectively, benefiting
157db96d56Sopenharmony_cifrom the solutions others have already created to common (and sometimes
167db96d56Sopenharmony_cieven rare!) problems, as well as potentially contributing their own
177db96d56Sopenharmony_cisolutions to the common pool.
187db96d56Sopenharmony_ci
197db96d56Sopenharmony_ciThis guide covers the distribution part of the process. For a guide to
207db96d56Sopenharmony_ciinstalling other Python projects, refer to the
217db96d56Sopenharmony_ci:ref:`installation guide <installing-index>`.
227db96d56Sopenharmony_ci
237db96d56Sopenharmony_ci.. note::
247db96d56Sopenharmony_ci
257db96d56Sopenharmony_ci   For corporate and other institutional users, be aware that many
267db96d56Sopenharmony_ci   organisations have their own policies around using and contributing to
277db96d56Sopenharmony_ci   open source software. Please take such policies into account when making
287db96d56Sopenharmony_ci   use of the distribution and installation tools provided with Python.
297db96d56Sopenharmony_ci
307db96d56Sopenharmony_ci
317db96d56Sopenharmony_ciKey terms
327db96d56Sopenharmony_ci=========
337db96d56Sopenharmony_ci
347db96d56Sopenharmony_ci* the `Python Package Index <https://pypi.org>`__ is a public
357db96d56Sopenharmony_ci  repository of open source licensed packages made available for use by
367db96d56Sopenharmony_ci  other Python users
377db96d56Sopenharmony_ci* the `Python Packaging Authority
387db96d56Sopenharmony_ci  <https://www.pypa.io/>`__ are the group of
397db96d56Sopenharmony_ci  developers and documentation authors responsible for the maintenance and
407db96d56Sopenharmony_ci  evolution of the standard packaging tools and the associated metadata and
417db96d56Sopenharmony_ci  file format standards. They maintain a variety of tools, documentation
427db96d56Sopenharmony_ci  and issue trackers on both `GitHub <https://github.com/pypa>`__ and
437db96d56Sopenharmony_ci  `Bitbucket <https://bitbucket.org/pypa/>`__.
447db96d56Sopenharmony_ci* :mod:`distutils` is the original build and distribution system first added
457db96d56Sopenharmony_ci  to the Python standard library in 1998. While direct use of :mod:`distutils`
467db96d56Sopenharmony_ci  is being phased out, it still laid the foundation for the current packaging
477db96d56Sopenharmony_ci  and distribution infrastructure, and it not only remains part of the
487db96d56Sopenharmony_ci  standard library, but its name lives on in other ways (such as the name
497db96d56Sopenharmony_ci  of the mailing list used to coordinate Python packaging standards
507db96d56Sopenharmony_ci  development).
517db96d56Sopenharmony_ci* `setuptools`_ is a (largely) drop-in replacement for :mod:`distutils` first
527db96d56Sopenharmony_ci  published in 2004. Its most notable addition over the unmodified
537db96d56Sopenharmony_ci  :mod:`distutils` tools was the ability to declare dependencies on other
547db96d56Sopenharmony_ci  packages. It is currently recommended as a more regularly updated
557db96d56Sopenharmony_ci  alternative to :mod:`distutils` that offers consistent support for more
567db96d56Sopenharmony_ci  recent packaging standards across a wide range of Python versions.
577db96d56Sopenharmony_ci* `wheel`_ (in this context) is a project that adds the ``bdist_wheel``
587db96d56Sopenharmony_ci  command to :mod:`distutils`/`setuptools`_. This produces a cross platform
597db96d56Sopenharmony_ci  binary packaging format (called "wheels" or "wheel files" and defined in
607db96d56Sopenharmony_ci  :pep:`427`) that allows Python libraries, even those including binary
617db96d56Sopenharmony_ci  extensions, to be installed on a system without needing to be built
627db96d56Sopenharmony_ci  locally.
637db96d56Sopenharmony_ci
647db96d56Sopenharmony_ci.. _setuptools: https://setuptools.readthedocs.io/en/latest/
657db96d56Sopenharmony_ci.. _wheel: https://wheel.readthedocs.io/
667db96d56Sopenharmony_ci
677db96d56Sopenharmony_ciOpen source licensing and collaboration
687db96d56Sopenharmony_ci=======================================
697db96d56Sopenharmony_ci
707db96d56Sopenharmony_ciIn most parts of the world, software is automatically covered by copyright.
717db96d56Sopenharmony_ciThis means that other developers require explicit permission to copy, use,
727db96d56Sopenharmony_cimodify and redistribute the software.
737db96d56Sopenharmony_ci
747db96d56Sopenharmony_ciOpen source licensing is a way of explicitly granting such permission in a
757db96d56Sopenharmony_cirelatively consistent way, allowing developers to share and collaborate
767db96d56Sopenharmony_ciefficiently by making common solutions to various problems freely available.
777db96d56Sopenharmony_ciThis leaves many developers free to spend more time focusing on the problems
787db96d56Sopenharmony_cithat are relatively unique to their specific situation.
797db96d56Sopenharmony_ci
807db96d56Sopenharmony_ciThe distribution tools provided with Python are designed to make it
817db96d56Sopenharmony_cireasonably straightforward for developers to make their own contributions
827db96d56Sopenharmony_ciback to that common pool of software if they choose to do so.
837db96d56Sopenharmony_ci
847db96d56Sopenharmony_ciThe same distribution tools can also be used to distribute software within
857db96d56Sopenharmony_cian organisation, regardless of whether that software is published as open
867db96d56Sopenharmony_cisource software or not.
877db96d56Sopenharmony_ci
887db96d56Sopenharmony_ci
897db96d56Sopenharmony_ciInstalling the tools
907db96d56Sopenharmony_ci====================
917db96d56Sopenharmony_ci
927db96d56Sopenharmony_ciThe standard library does not include build tools that support modern
937db96d56Sopenharmony_ciPython packaging standards, as the core development team has found that it
947db96d56Sopenharmony_ciis important to have standard tools that work consistently, even on older
957db96d56Sopenharmony_civersions of Python.
967db96d56Sopenharmony_ci
977db96d56Sopenharmony_ciThe currently recommended build and distribution tools can be installed
987db96d56Sopenharmony_ciby invoking the ``pip`` module at the command line::
997db96d56Sopenharmony_ci
1007db96d56Sopenharmony_ci    python -m pip install setuptools wheel twine
1017db96d56Sopenharmony_ci
1027db96d56Sopenharmony_ci.. note::
1037db96d56Sopenharmony_ci
1047db96d56Sopenharmony_ci   For POSIX users (including macOS and Linux users), these instructions
1057db96d56Sopenharmony_ci   assume the use of a :term:`virtual environment`.
1067db96d56Sopenharmony_ci
1077db96d56Sopenharmony_ci   For Windows users, these instructions assume that the option to
1087db96d56Sopenharmony_ci   adjust the system PATH environment variable was selected when installing
1097db96d56Sopenharmony_ci   Python.
1107db96d56Sopenharmony_ci
1117db96d56Sopenharmony_ciThe Python Packaging User Guide includes more details on the `currently
1127db96d56Sopenharmony_cirecommended tools`_.
1137db96d56Sopenharmony_ci
1147db96d56Sopenharmony_ci.. _currently recommended tools: https://packaging.python.org/guides/tool-recommendations/#packaging-tool-recommendations
1157db96d56Sopenharmony_ci
1167db96d56Sopenharmony_ci.. index::
1177db96d56Sopenharmony_ci   single: Python Package Index (PyPI)
1187db96d56Sopenharmony_ci   single: PyPI; (see Python Package Index (PyPI))
1197db96d56Sopenharmony_ci
1207db96d56Sopenharmony_ci.. _publishing-python-packages:
1217db96d56Sopenharmony_ci
1227db96d56Sopenharmony_ciReading the Python Packaging User Guide
1237db96d56Sopenharmony_ci=======================================
1247db96d56Sopenharmony_ci
1257db96d56Sopenharmony_ciThe Python Packaging User Guide covers the various key steps and elements
1267db96d56Sopenharmony_ciinvolved in creating and publishing a project:
1277db96d56Sopenharmony_ci
1287db96d56Sopenharmony_ci* `Project structure`_
1297db96d56Sopenharmony_ci* `Building and packaging the project`_
1307db96d56Sopenharmony_ci* `Uploading the project to the Python Package Index`_
1317db96d56Sopenharmony_ci* `The .pypirc file`_
1327db96d56Sopenharmony_ci
1337db96d56Sopenharmony_ci.. _Project structure: https://packaging.python.org/tutorials/packaging-projects/#packaging-python-projects
1347db96d56Sopenharmony_ci.. _Building and packaging the project: https://packaging.python.org/tutorials/packaging-projects/#creating-the-package-files
1357db96d56Sopenharmony_ci.. _Uploading the project to the Python Package Index: https://packaging.python.org/tutorials/packaging-projects/#uploading-the-distribution-archives
1367db96d56Sopenharmony_ci.. _The .pypirc file: https://packaging.python.org/specifications/pypirc/
1377db96d56Sopenharmony_ci
1387db96d56Sopenharmony_ci
1397db96d56Sopenharmony_ciHow do I...?
1407db96d56Sopenharmony_ci============
1417db96d56Sopenharmony_ci
1427db96d56Sopenharmony_ciThese are quick answers or links for some common tasks.
1437db96d56Sopenharmony_ci
1447db96d56Sopenharmony_ci... choose a name for my project?
1457db96d56Sopenharmony_ci---------------------------------
1467db96d56Sopenharmony_ci
1477db96d56Sopenharmony_ciThis isn't an easy topic, but here are a few tips:
1487db96d56Sopenharmony_ci
1497db96d56Sopenharmony_ci* check the Python Package Index to see if the name is already in use
1507db96d56Sopenharmony_ci* check popular hosting sites like GitHub, Bitbucket, etc to see if there
1517db96d56Sopenharmony_ci  is already a project with that name
1527db96d56Sopenharmony_ci* check what comes up in a web search for the name you're considering
1537db96d56Sopenharmony_ci* avoid particularly common words, especially ones with multiple meanings,
1547db96d56Sopenharmony_ci  as they can make it difficult for users to find your software when
1557db96d56Sopenharmony_ci  searching for it
1567db96d56Sopenharmony_ci
1577db96d56Sopenharmony_ci
1587db96d56Sopenharmony_ci... create and distribute binary extensions?
1597db96d56Sopenharmony_ci--------------------------------------------
1607db96d56Sopenharmony_ci
1617db96d56Sopenharmony_ciThis is actually quite a complex topic, with a variety of alternatives
1627db96d56Sopenharmony_ciavailable depending on exactly what you're aiming to achieve. See the
1637db96d56Sopenharmony_ciPython Packaging User Guide for more information and recommendations.
1647db96d56Sopenharmony_ci
1657db96d56Sopenharmony_ci.. seealso::
1667db96d56Sopenharmony_ci
1677db96d56Sopenharmony_ci   `Python Packaging User Guide: Binary Extensions
1687db96d56Sopenharmony_ci   <https://packaging.python.org/guides/packaging-binary-extensions/>`__
1697db96d56Sopenharmony_ci
1707db96d56Sopenharmony_ci.. other topics:
1717db96d56Sopenharmony_ci
1727db96d56Sopenharmony_ci   Once the Development & Deployment part of PPUG is fleshed out, some of
1737db96d56Sopenharmony_ci   those sections should be linked from new questions here (most notably,
1747db96d56Sopenharmony_ci   we should have a question about avoiding depending on PyPI that links to
1757db96d56Sopenharmony_ci   https://packaging.python.org/en/latest/mirrors/)
176