Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Grouping Dependencies

00:00 Let’s talk about managing a group of dependencies. A cool feature Poetry has that you probably can’t get using other tools like regular pip. Poetry allows you to keep logically related dependencies separate from your main runtime dependencies.

00:15 For example, you could choose to separate development and some test dependencies. These are packages you need during development or for testing, but not in production.

00:25 For example, you might need testing tools like pytest or type checkers like mypy or linters like flake8 or isort.

00:33 To add a development dependency, you can group them and use the --group flag. Here is how to add a few dependencies to a group called dev.

00:44 You can run the command poetry add --group dev being the name of the group, then the dependencies like black, flake8, or isort.

00:57 This should add those dependencies and their sub-dependencies,

01:04 and you can add some dependencies to another group called test with poetry add --group test being the name of the new group, and then the dependencies like pytest and faker.

01:19 You should also see those dependencies added.

01:24 If you inspect your pyproject.toml file, you’ll see that the development dependencies are stored separately under tool.poetry.group.dev.dependencies, and tool.poetry.group.test.dependencies.

01:40 These new sections start with the name tool.poetry.group, and end with the word dependencies. The part in the middle must be a unique group name, in your case, dev and test.

01:54 If you don’t provide any group name, Poetry puts the specified package in an implicit main group, the tool.poetry.dependencies section. So you can’t use the name main for one of your groups because it’s been reserved.

Become a Member to join the conversation.