Hi everyone,
I’d like to start a discussion on an idea relating to extras, in order to see if there is sufficient consensus to warrant a PEP.
Background
As part of the PEP 771 discussion, @aragilar mentioned the following idea:
In general, discoverability of extras is not great at the moment. For example, as far as I can tell, pip
and uv
can’t easily tell you what extras exist for a package (though I’m happy to be corrected on this), and PyPI doesn’t show any information about extras. Part of the issue is that even if it were possible to list extras, it’s not always clear what each one does based just on the name.
If it were possible to document extras in a standardized way, it could make it easier for tools to improve discoverability.
Example
Documenting extras could, for example, be done via a new section in project metadata which would list a description for each extra, such as:
[project.optional-dependencies.descriptions]
recommended = "Dependencies that are recommended for most users"
docs = "Dependencies needed for building the documentation"
jupyter = "Dependencies that can optionally provide enhanced functionality in Jupyter notebooks and lab"
[project.optional-dependencies]
recommended = [
"scipy",
"matplotlib",
]
docs = [
"sphinx"
]
jupyter = [
"ipywidgets",
]
Of course, if well named, extras might not always need a description (e.g. recommended
and test
), although even here it’s not really obvious what jupyter
does without a description. Does it install Jupyter notebook/lab? Or does it add functionality for users who already have Jupyter notebook/lab? Is it required for users who want to use Jupyter (but still listed as optional in general because not everyone uses Jupyter)?
There might also be cases where it would be useful to tell the user about interactions between different extras, for instance stating that the user should pick one of a few options but not install all extras, and so on.
What this could be used for
If this did become a PEP, I don’t think it should mandate any particular way tools should use the information. But as an example, one could imagine command-line tools implementing something like:
$ pip extras package
recommended: Dependencies that are recommended for most users
test: Dependencies needed for building the documentation
jupyter: Dependencies that can optionally provide enhanced functionality in Jupyter notebooks and lab
or this could be part of e.g. pip show
or another similar command. A similar approach could be taken in uv
and other tools.
Currently, all these tools could already have a way to list the extras if they wanted, and this could already be useful, but it would be much more useful in general if there were some kind of description associated with them.
Another example of usage would be to list available extras on PyPI. Again, there’s no reason this couldn’t be done already, but having a description would make this a lot more useful.
Prior art
Tox uses a similar approach, where it’s possible to describe the different factors:
description =
run tests
recdeps: with recommended optional dependencies
alldeps: with all optional and test dependencies
and it then makes it possible for tox -l
to list environments with useful information for the user, such as:
$ tox -l
py311-test-recdeps -> run tests with recommended optional dependencies
py311-test-alldeps -> run tests with all optional and test dependencies
Open questions and next steps
There are a lot of open questions and details to figure out related to this idea, such as whether we would want a single description for a given extra, or both a short (with character limit) and long (with no limit) description; whether PyPI would expose this metadata to tools so that they don’t have to download a package to find out what extras are present; whether having a description for a non-existent extra should be silently ignored or raise errors; and so on.
However, at this point, I’m more interested in understanding whether there is appetite for something like this, in which case we can try and figure out all the details. Alternatively, maybe it’s something that is not desirable conceptually?