Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between extras and groups in poetry?

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.

  1. Are groups just a syntactic sugar that is going to simplify definition of optional dependencies?
  2. If yes, will extras be depracated in favour of groups?
  3. If not, what's the difference between them and how both can coexist?
like image 345
dzieciou Avatar asked Sep 04 '25 01:09

dzieciou


2 Answers

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.

like image 90
GopherM Avatar answered Sep 07 '25 18:09

GopherM


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

like image 40
Felix Yuan Avatar answered Sep 07 '25 18:09

Felix Yuan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!