Poetry installation and usage
Poetry installation and usage The official installation guide is very well written, and it is recommended to install via pipx. Installing Poetry generally should not pose any problems, as long as pipx is working properly. Poetry assumes your package contains a package with the same name as In the pyproject.toml file, the For example: Project structure: caret e.g. tilde e.g. wildcard e.g. Inequality e.g. When using e.g. Poetry offers dependency groups to manage project dependencies, such as those used only for tests. You can declare a dependency group using For example: This groups libraries like The Poetry documentation states: Dependency groups (except the implicit Adding Dependencies to a Group When using If the dependency group does not exist, it will be created automatically. Removing Dependencies from a Group Use Creating Optional Groups You can add Installing/Excluding Groups By default, all groups except those marked optional are installed automatically with You can specify which dependency groups to include or exclude using the When used together, If you want to install only the runtime dependencies of the project, use the If you want to install only the package at the project’s root and skip other dependencies, use the Synchronization – Installing Dependencies and Removing Unnecessary Packages Poetry supports dependency synchronization, which ensures that the dependencies locked in the You can use the This command will: It can be combined with the The primary dependencies are always installed. For example, if you have groups [main], [dev], [docs] and run Using Poetry
Installation
Basic Usage
Create a Project
poetry new poetry-demotool.poetry.name located in the root of your project. If this is not the case, populate tool.poetry.packages to specify your packages and their locations.tool.poetry.name must match the name value. If they differ, you need to specify it using tool.poetry.packages
[]
= "my_project"
[]
= "my_project"
[]
= "src"
Existing Project Managed with Poetry
Poetry Dependencies
Adding Dependencies
[]
= "^2.1"
Supported Dependency Formats in Poetry
^1.2.3 → >=1.2.3 <2.0.0~1.2.3 → >=1.2.3 <1.3.01.* → >=1.0.0 <2.0.0>= 1.2.0poetry add, you can use the @ symbol, which is equivalent to ==, but you can also utilize Poetry’s modifiers
Managing Dependencies
tool.poetry.group.<group>
pytest and pytest-mock under the test group.main group) should include only the packages you need during development. They are installed only with Poetry. To declare a set of dependencies that add optional features at runtime, use extras. End users can install extras using pip.poetry add, add the --group (or -G) parameter
poetry remove to delete packages from a specific group
optional = true to mark a group as optional, so that it is not automatically installed with poetry install[]
= true
[]
= "*"
poetry install--with or --without options
--without takes precedence over --with. For example, the following command will install only the dependencies specified in the optional test group.
--only main option:
--only-root option.
poetry.lock file are the only ones present in your environment by removing any unneeded packages.--sync parameter with poetry install
--with or --without options
poetry install --with docs --sync, then [main] and [docs] will be installed while [dev] will be omitted.