So far I have used poetry extras to install optional dependencies. For instance, in pyproject.toml
I have defined
[tool.poetry.dependencies]
...
jupyter = { version = "^1.0.0", optional = true }
[tool.poetry.extras]
notebooks = ["jupyter"...]
and then I could install optional dependencies with poetry install -E notebooks
.
Now I can see that poetry is going to support groups. My intuition is that the example above could be replaced with:
[tool.poetry.group.notebooks.dependencies]
jupyter = "^1.0.0"...
and then installed with poetry install --with notebooks
.
Now I wonder how groups relate to extras.
From the official documentation here https://python-poetry.org/docs/managing-dependencies/
Dependency groups, other than the implicit
main
group, must only contain dependencies you need in your development process. Installing them is only possible by using Poetry.
To declare a set of dependencies, which add additional functionality to the project during runtime, use extras instead. Extras can be installed by the end user using
pip
.
So if you plan to install something using pip
- then extras
is the choice.
Installing groups is only possible using Poetry.
'group' is something like you split the whole dependencies into multi files, such as requirements.txt, requirements_test.txt, requirements_doc.txt。You choose which requirements file to install based on your need, this usually happens during development.
'extra' is something like feature toggles of your published package, the external user choose which extras to install based on the need of his own project。
'group' is designed for internal developer, it applies for both package and application development. However, 'extra' is designed for external pypi user, it applies only for package.
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