Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is 'extra' in pypi dependency?

In requires_dist section of a package's json response from pypi, it is given:

requires_dist : [
    "bcrypt; extra == 'bcrypt'",
    "argon2-cffi (>=16.1.0); extra == 'argon2'"
]

can anyone make it clear the second statement of each dependency, extra == 'bcrypt' and extra == 'argon2'?

like image 280
All Іѕ Vаиітy Avatar asked Sep 24 '18 08:09

All Іѕ Vаиітy


People also ask

What is extras in Python?

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 ).

What packages are in PyPI?

PyPI primarily hosts Python packages in the form of archives called sdists (source distributions) or precompiled "wheels." PyPI as an index allows users to search for packages by keywords or by filters against their metadata, such as free software license or compatibility with POSIX.

How do you resolve dependency conflicts in pip?

Unfortunately, pip makes no attempt to resolve dependency conflicts. For example, if you install two packages, package A may require a different version of a dependency than package B requires. Pip can install from either Source Distributions (sdist) or Wheel (. whl) files.

Is everything on PyPI safe?

They are not safe. It would be easy to upload malicious code to PyPI. That's debatable.

What is the PyPI package index?

The Python Package Index (PyPI) is a repository of software for the Python programming language. PyPI helps you find and install software developed and shared by the Python community. Learn about installing packages. Package authors use PyPI to distribute their software. Learn how to package your Python code for PyPI.

What is PyPI in Python?

The Python Package Index (PyPI) is a repository of software for the Python programming language. PyPI helps you find and install software developed and shared by the Python community. Learn about installing packages. Package authors use PyPI to distribute their software.

Why can't I Find my Python dependency in the Package Index?

Your Python dependency can't be found the Python Package Index, and the library does not have any external dependencies, such as dist-packages. You want to use plugin-specific functionality, such as modifying the Airflow web interface. Your Python dependency can be found on the Python Package Index and has no external dependencies.

How many users does PyPI have?

371,853 users. The Python Package Index (PyPI) is a repository of software for the Python programming language. PyPI helps you find and install software developed and shared by the Python community.


1 Answers

Extras are dependencies you can install in addition to the regular dependencies, if you ask for them explicitly. See them as optional features.

You can install these with the name after the ==, with the name of the package. For example, if you install somepackage and want to add the bcrypt optional feature, use:

pip install somepackage[bcrypt]

or

pip install somepackage[argon2]

or, to include both optional extras, separate the names with commas:

pip install somepackage[bcrypt,argon2]

although using somepackage[...] multiple times also works as pip is smart enough to know that the main package is already installed.

pip (or whatever other package install tool) maps names listed in <packagename>[<extras_name>(,...)] to those entries in the requires_dict that use the <dependency_spec>; extra == '<extras_name>' format, adding on the dependency_specs to the list of things to install.

See Installing Setuptools "Extras" in the Installing Packages section of the Python Packaging User Guide.

It is up to the installed package itself to detect if all the dependencies for optional extra features are installed. A common pattern is to use try...except ImportError: guards to test for such extra dependencies being available.

like image 165
Martijn Pieters Avatar answered Oct 21 '22 14:10

Martijn Pieters