I see more and more commands like this:
$ pip install "splinter[django]"
What do these square brackets do?
The syntax that you are using is:
pip install "project[extra]"
In your case, you are installing
the splinter
package which has the added support for django
.
• pip install splinter django
would install two packages named splinter
and django
.
• pip install splinter[django]
, on the other hand, installs splinter, but it also installs optional dependencies defined by splinter using the keyword in the brackets. In this case, as of 2024-05-15 it's Django
, lxml
and cssselect
.
Note that the keyword in brackets has nothing to do with the django
package itself, but is just a string defined by the splinter
package for a particular set of dependencies that also get installed. How the argument django
is interpreted depends on the build system, but any setuptools-based build system (including most instances of setup.py
) will likely just use them as a hook for optional dependencies.
It's worth noting that the syntax supports using multiple keywords, e.g.:
pip install "splinter[django,flask,selenium]"
Kudos to @chepner for adding context in the comments.