Poetry is a dependency management and packaging tool for Python. It simplifies dependency management by providing a unified interface to manage packages and their dependencies.
You can install Poetry using pip:
pip install poetry
Check the [official documentation](poetry config virtualenvs.create false --local) for more information.
To change the Python version used by Poetry, run:
poetry env use /full/path/to/python
poetry env use python3.10
poetry env use 3.7
After that, run poetry update
to update the dependencies. This will update the pyproject.toml
and poetry.lock
files with the new versions and also install the environment.
To add a dependency, run:
poetry add package-name
This will install the latest version of the package and add it to your pyproject.toml file taking in account the other dependencies so it doesn't break anything.
To update a dependency, run:
poetry update
poetry update package-name
This will update the package(s) to the latest version and update the pyproject.toml file.
To install the dependencies for a project, run:
poetry install
This will install all the dependencies listed in the pyproject.toml file.
You can define scripts in the pyproject.toml file and run them with Poetry. For example, to run a script called test:
[tool.poetry.scripts]
test = "pytest"
You can run the script with:
poetry run test
To build your project and create a distributable package, run:
poetry build
This will create a dist directory with the distributable package(s).
To publish your package to a package index (such as PyPI), you can use Poetry's publish command. Before publishing, make sure you have configured your credentials and set the appropriate repository in your pyproject.toml file.
poetry publish
This will package and upload your package to the configured repository.
For more information and detailed documentation, check out the official Poetry documentation.