Skip to content

'poetry show' could output more easily machine-readable output #10451

@colindean

Description

@colindean

Issue Kind

Brand new capability

Description

I've got a need to know what version of a dependency is installed and get other information about that dependency in a machine readable format. The output of poetry show lists a lot of useful information, but parsing it with tooling is hard.

$ poetry show requests
 name         : requests
 version      : 2.32.4
 description  : Python HTTP for Humans.

dependencies
 - certifi >=2017.4.17
 - charset_normalizer >=2,<4
 - idna >=2.5,<4
 - urllib3 >=1.21.1,<3

required by
 - gcsfs requires *
 - google-api-core requires >=2.18.0,<3.0.0
 - google-cloud-bigquery requires >=2.21.0,<3.0.0
 - google-cloud-storage requires >=2.18.0,<3.0.0dev
 - google-genai requires >=2.28.1,<3.0.0
 - kubernetes requires *
 - pyoauthtarget requires >=2.31.0
 - requests-oauthlib requires >=2.0.0
 - requests-toolbelt requires >=2.0.1,<3.0.0

To get the version of requests, I'd need to use

poetry show requests | awk '/version/ { print $3 }'

To suit my exact case, an option such as --version-only would suffice.

but there's other information in there that could be useful, too. I'd love for this output to be in JSON format, e.g.

{
  "name": "requests",
  "version": "2.32.4",
  "description": "Python HTTP for Humans.",
  "dependencies": {
    "certifi": ">=2017.4.17",
    "charset_normalizer": ">=2,<4",
    "idna": ">=2.5,<4",
    "urllib3": ">=1.21.1,<3"
  },
  "required_by": {
    "gcsfs": "*",
    "requests-oauthlib": ">=2.0.0",
    "requests-toolbelt": ">=2.0.1,<3.0.0"
  }
}

Then I could do1:

poetry show requests | jq .version

Impact

Having this would enable users to poll poetry itself for information it already presents but doesn't do so in a way that other tooling can easily consume it.

While a lockfile has this information, reading it requires additional tooling and an understanding of the lockfile format.

Workarounds

With a TOML reader available, I could read poetry.lock, but in my case, I don't, except perhaps using Poetry's venv which would guarantee that tomllib or toml are available.

Footnotes

  1. I recognize the irony in wanting JSON instead of using awk but I reckon it's better for the other sections.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureFeature requests/implementationsstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions