Some Python packages have extra features that can be installed by putting them into brackets such as the security extra for the requests package:
pip install requests[security]
Is there a way to list all the extras of a given package ?
I cannot find anything like that in the pip documentation.
Python extras are a way for Python projects to declare that extra dependencies are required for additional functionality. For example, requests has several standard dependencies (e.g. urllib3 ). But it also declares an extra named requests[security] , which lists additional dependencies (e.g. cryptography ).
Pipenv. This command will list all packages installed, including any dependencies that are found in a Pipfile.
There are two open feature requests in pip about this:
In the meantime, a workaround using importlib_metadata's API and working for already installed packages has been provided by jaraco.
Copy-pasting it below:
An even better alternative would be to use importlib_metadata, which has an API.
>>> import importlib_metadata >>> importlib_metadata.metadata('xonsh').get_all('Provides-Extra') ['linux', 'mac', 'proctitle', 'ptk', 'pygments', 'win'] >>> importlib_metadata.metadata('xonsh').get_all('Requires-Dist') ["distro; extra == 'linux'", "gnureadline; extra == 'mac'", "setproctitle; extra == 'proctitle'", "prompt-toolkit; extra == 'ptk'", "pygments (>=2.2); extra == 'pygments'", "win-unicode-console; extra == 'win'"]
And use packaging to parse them:
>>> req = next(map(packaging.requirements.Requirement, importlib_metadata('xonsh').get_all('Requires-Dist'))) >>> req.name 'distro' >>> req.specifier <SpecifierSet('')> >>> req.extras set() >>> req.marker <Marker('extra == "linux"')>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With