Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Poetry specify dependency on `sentry-sdk[flask]`

I’m trying to add support for Sentry to an existing Python Flask application that uses Python Poetry for dependency management.

The Sentry docs say to run this:

pip install --upgrade 'sentry-sdk[flask]

That works. But I want to convert that into a pyproject.toml dependency entry for Python Poetry. If I try just this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[tool.poetry.dependencies]
# <snip>
sentry-sdk = "1.5.12"

I get a SolverProblemError:

… depends on sentry-sdk (1.5.12) which doesn’t match any versions, version solving failed.

If I try:

[tool.poetry.dependencies]
# <snip>
sentry-sdk[flask] = "1.5.12"

I get Invalid TOML file.

How do I convert this pip dependency to Python pyproject.toml format?

>Solution :

This is how you can specify a dependency with extras:

[tool.poetry.dependencies]
python = "^3.9"
sentry-sdk = {extras = ["flask"], version = "1.5.12"}

I’m not sure where this is documented, couldn’t find it in the docs.

You can also achieve this by running:

poetry add sentry-sdk[flask]==1.5.12
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading