-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add discussion "Distribution package vs. import package" #1426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3518185
Add discussion "Distribution package vs. import package"
jeanas 176f956
Update source/discussions/distribution-package-vs-import-package.rst
jeanas 790e7cf
Update source/discussions/distribution-package-vs-import-package.rst
jeanas fe9378a
Mention attrs as a distribution package which provides several import…
jeanas 92380ec
Link to Python docs for exact rules on valid identifiers
jeanas a7592e8
Rewrap
jeanas 38675a1
Address review comments
jeanas 49368ea
Merge branch 'main' into distribution-vs-import-package
jeanas d4164d2
The PyPI
jeanas 62273fe
Python software -> Python libraries and tools
jeanas bbbab1a
Clarify reference to Linux distro packages
jeanas 0335a1f
Add importlib pointer
jeanas 3b42e3f
Syntax fixes
jeanas 9b3655c
Missing word
jeanas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
source/discussions/distribution-package-vs-import-package.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
.. _distribution-package-vs-import-package: | ||
|
||
======================================= | ||
Distribution package vs. import package | ||
======================================= | ||
|
||
A number of different concepts are commonly referred to by the word | ||
"package". This page clarifies the differences between two distinct but | ||
related meanings in Python packaging, "distribution package" and "import | ||
package". | ||
|
||
What's a distribution package? | ||
============================== | ||
|
||
A distribution package is a piece of software that you can install. | ||
jeanas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Most of the time, this is synonymous with "project". When you type ``pip | ||
install pkg``, or when you write ``dependencies = ["pkg"]`` in your | ||
``pyproject.toml``, ``pkg`` is the name of a distribution package. When | ||
you search or browse the PyPI_, the most widely known centralized source for | ||
installing Python libraries and tools, what you see is a list of distribution | ||
packages. Alternatively, the term "distribution package" can be used to | ||
refer to a specific file that contains a certain version of a project. | ||
|
||
Note that in the Linux world, a "distribution package", | ||
most commonly abbreviated as "distro package" or just "package", | ||
is something provided by the system package manager of the `Linux distribution <distro_>`_, | ||
which is a different meaning. | ||
|
||
|
||
What's an import package? | ||
========================= | ||
|
||
An import package is a Python module. Thus, when you write ``import | ||
pkg`` or ``from pkg import func`` in your Python code, ``pkg`` is the | ||
name of an import package. More precisely, import packages are special | ||
Python modules that can contain submodules. For example, the ``numpy`` | ||
package contains modules like ``numpy.linalg`` and | ||
``numpy.fft``. Usually, an import package is a directory on the file | ||
system, containing modules as ``.py`` files and subpackages as | ||
subdirectories. | ||
webknjaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
You can use an import package as soon as you have installed a distribution | ||
package that provides it. | ||
|
||
|
||
What are the links between distribution packages and import packages? | ||
===================================================================== | ||
|
||
Most of the time, a distribution package provides one single import | ||
package (or non-package module), with a matching name. For example, | ||
``pip install numpy`` lets you ``import numpy``. | ||
|
||
However, this is only a convention. PyPI and other package indices *do not | ||
enforce any relationship* between the name of a distribution package and the | ||
import packages it provides. (A consequence of this is that you cannot blindly | ||
install the PyPI package ``foo`` if you see ``import foo``; this may install an | ||
unintended, and potentially even malicious package.) | ||
|
||
A distribution package could provide an import package with a different | ||
name. An example of this is the popular Pillow_ library for image | ||
processing. Its distribution package name is ``Pillow``, but it provides | ||
the import package ``PIL``. This is for historical reasons: Pillow | ||
started as a fork of the PIL library, thus it kept the import name | ||
``PIL`` so that existing PIL users could switch to Pillow with little | ||
effort. More generally, a fork of an existing library is a common reason | ||
for differing names between the distribution package and the import | ||
package. | ||
|
||
On a given package index (like PyPI), distribution package names must be | ||
unique. On the other hand, import packages have no such requirement. | ||
Import packages with the same name can be provided by several | ||
jeanas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
distribution packages. Again, forks are a common reason for this. | ||
|
||
Conversely, a distribution package can provide several import packages, | ||
although this is less common. An example is the attrs_ distribution | ||
package, which provides both an ``attrs`` import package with a newer | ||
API, and an ``attr`` import package with an older but supported API. | ||
|
||
|
||
How do distribution package names and import package names compare? | ||
jeanas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
=================================================================== | ||
|
||
Import packages should have valid Python identifiers as their name (the | ||
:ref:`exact rules <python:identifiers>` are found in the Python | ||
documentation). In particular, they use underscores ``_`` as word | ||
jeanas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
separator and they are case-sensitive. | ||
|
||
On the other hand, distribution packages can use hyphens ``-`` or | ||
underscores ``_``. They can also contain dots ``.``, which is sometimes | ||
used for packaging a subpackage of a :ref:`namespace package | ||
<packaging-namespace-packages>`. For most purposes, they are insensitive | ||
to case and to ``-`` vs. ``_`` differences, e.g., ``pip install | ||
Awesome_Package`` is the same as ``pip install awesome-package`` (the | ||
precise rules are given in the :ref:`name normalization specification | ||
<name-normalization>`). | ||
|
||
|
||
jeanas marked this conversation as resolved.
Show resolved
Hide resolved
jeanas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.. _distro: https://en.wikipedia.org/wiki/Linux_distribution | ||
.. _PyPI: https://pypi.org | ||
.. _Pillow: https://pypi.org/project/Pillow | ||
.. _attrs: https://pypi.org/project/attrs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.