Skip to content

uv pip tree machine readable output #4711

Closed as not planned
Closed as not planned

Description

@ibraheemdev

e.g. JSON with -j. This is useful for interacting with graph tools such as mermaid.

Activity

  1. added
    area:cli
    on Jul 1, 2024
  2. zanieb commented on Jul 1, 2024

    @zanieb
    Member

    I think we should probably use --format json for consistency with other interfaces?

  3. added
    help wanted
    on Jul 1, 2024
  4. zanieb commented on Jul 1, 2024

    @zanieb
    Member

    See also #411

  5. ChannyClaus commented on Jul 3, 2024

    @ChannyClaus
    Contributor

    should this be part of uv pip tree or uv pip list? uv pip list --format json seems to already print something very similar to what pipdeptree --json prints:

    $ uv pip list --format json | jq 
    [
      {
        "name": "certifi",
        "version": "2024.6.2"
      },
      {
        "name": "charset-normalizer",
        "version": "3.3.2"
      },
      {
        "name": "idna",
        "version": "3.7"
      },
      {
        "name": "requests",
        "version": "2.32.3"
      },
      {
        "name": "urllib3",
        "version": "2.2.2"
      }
    ]
    

    additionally the output of pipdeptree --json doesn't seem to necessarily relate to the concept of tree, since when there's a nested dependency, it doesn't actually nest it in the json output.

    thoughts @dsully @kdeldycke?

  6. kdeldycke commented on Jul 3, 2024

    @kdeldycke

    Oh I'm not really picky about the shape of the JSON output, as long as it is machine readable.

    That's because I'm only interested in creating a Mermaid diagram to visualize dependencies like so: https://kdeldycke.github.io/meta-package-manager/install.html#python-dependencies

    So whatever the JSON looks like, I'll have to write a script to generate the .mmd file out of uv pip tree output.

  7. paveldikov commented on Jul 24, 2024

    @paveldikov
    Contributor

    I'm interested in this in an SBOM context. A JSON representation of the tree would be a fantastic precursor format that can be easily post-processed into one of the many SBOM formats out there. In particular, being able to distinguish between direct and transitive dependencies is key.

    (not sure if doing this in uv pip list would work for this usage? If it does, great!)

  8. kdeldycke commented on Aug 2, 2024

    @kdeldycke

    Lol. I just realized I solved this problem myself, as my Meta Package Manager CLI allows you to:

    • Export a JSON list of installed packages from a uv environment:

      $ mpm --uv --output-format json installed
      
      {
          "uv": {
              "errors": [],
              "id": "uv",
              "name": "UV",
              "packages": [
                  {
                      "id": "alabaster",
                      "installed_version": "0.7.16",
                      "name": null
                  },
                  {
                      "id": "arrow",
                      "installed_version": "1.3.0",
                      "name": null
                  },
                  {
                      "id": "attrs",
                      "installed_version": "23.2.0",
                      "name": null
                  },
      ...
    • Export an SBOM of a uv environment:

      $ mpm --uv sbom --spdx                   
      info: User selection of managers by priority: > uv
      info: Managers dropped by user: None
      info: Print SPDX export to <stdout>
      info: Export packages from uv...
      
      {
          "SPDXID": "SPDXRef-DOCUMENT",
          "creationInfo": {
              "created": "2024-08-02T23:29:10Z",
              "creators": [
                  "Tool: meta-package-manager-5.18.1"
              ]
          },
          "dataLicense": "CC0-1.0",
          "name": "macOS-Darwin-23.6.0-arm64",
          "spdxVersion": "SPDX-2.3",
          "documentNamespace": "https://github.com/kdeldycke/meta-package-manager/releases/tag/v5.18.1/fdcf50b29504cc4c0df620af2283ed3",
          "packages": [
              {
                  "SPDXID": "SPDXRef-pkg-uv-alabaster-0.7.16",
                  "downloadLocation": "https://www.example.com",
                  "externalRefs": [
                      {
                          "referenceCategory": "PACKAGE_MANAGER",
                          "referenceLocator": "pkg:uv/[email protected]",
                          "referenceType": "purl"
                      }
                  ],
                  "filesAnalyzed": false,
                  "name": "alabaster",
                  "primaryPackagePurpose": "INSTALL",
                  "supplier": "Organization: UV",
                  "versionInfo": "0.7.16"
              },
              {
                  "SPDXID": "SPDXRef-pkg-uv-arrow-1.3.0",
                  "downloadLocation": "https://www.example.com",
                  "externalRefs": [
                      {
                          "referenceCategory": "PACKAGE_MANAGER",
                          "referenceLocator": "pkg:uv/[email protected]",
                          "referenceType": "purl"
                      }
                  ],
                  "filesAnalyzed": false,
                  "name": "arrow",
                  "primaryPackagePurpose": "INSTALL",
                  "supplier": "Organization: UV",
                  "versionInfo": "1.3.0"
              },
      ...
  9. dsully commented on Oct 12, 2024

    @dsully

    I'm not picky about the output of the JSON either, and it doesn't need to take a tree shape.

    Just represent the consumers and producers in the environment / lock file.

    Alternatively if there was a consumable crate that I could depend on to walk the tree/lock file that would almost be better.

  10. kapilt commented on Jun 25, 2025

    @kapilt

    I'd prefer a tree shape to be able to understand the top level depend, ie which package in a workspace pulled in this dependency.

  11. cr-klarna commented on Aug 29, 2025

    @cr-klarna

    interested in any ongoing work here. I recognize that people want to at least distinguish between transitive and direct dependencies, and this is ofc doable at a glance, though there seems to be no specification on how people want it to look like. Personally I don't mind a flattened list approach for our needs where we would just have packages listed with the dependency type as a field in the object. Just gonna throw a suggestion:

    e.g.

    [
    {
      "package": "name",
      "versionConstraint": ">x.x.x",
      "version": "x.x.x",
      "type": "direct",
      "dependencies": [
        {"package": "some_transitive_package", "versionConstraint": "x.x.x"},
        ...
      ]
    },
    ...
    ]
    

    for the dependencies, we would only need the package identifier and the constraint. We can collect the actual package info in the flat list and you would be able to build from this a graph including the constraints each dependency had, vs the actual resolved version. Also trivial to format this way since we have the tree, it's just leaf-first traversal at that point to turn them into this I assume?

  12. cr-klarna commented on Sep 4, 2025

    @cr-klarna

    https://github.com/cr-klarna/uv/tree/add-tree-json-format
    Ended up needing to sacrifice some initial info, but as an example what I have now would generate for example if given the project:

    [project]
    name = "project"
    version = "0.1.0"
    requires-python = ">=3.12"
    dependencies = [
        "iniconfig",
        "pip",
        "anyio < 2 ; sys_platform == 'win32'",
        "anyio > 2 ; sys_platform == 'linux'",
        "flask[dotenv,async]",
    ]
    
    [dependency-groups]
    dev = [
        "plotly",
        "pip",
    ]
    test = [
        "pytest",
    ]

    you would get the following (heavily truncated):

    [
          {
            "name": "project",
            "version": "0.1.0",
            "dependency_type": "project",
            "extras": [],
            "dependencies": [
              {
                "name": "pip",
                "version": "24.0",
                "extra": ""
              },...
           ],
           "group": ""
           },
            ...
          {
            "name": "flask",
            "version": "3.0.2",
            "dependency_type": "direct",
            "extras": [
              "async",
              "dotenv"
            ],
            "dependencies": [
              {
                "name": "python-dotenv",
                "version": "1.0.1",
                "extra": "dotenv"
              },
              {
                "name": "asgiref",
                "version": "3.8.1",
                "extra": "async"
              },
           ],
           group: "",
          },
          {
            "name": "pip",
            "version": "24.0",
            "dependency_type": "direct",
            "extras": [],
            "dependencies": [],
            "group": "dev"
          },
          ...
    ]
    

    If people are okay with that or don't care within a day or so I'll start finalizing this including some flag logic (for example --invert makes no sense with json formats)

  13. woodruffw commented on Nov 20, 2025

    @woodruffw
    Member

    Triage: #16523 added JSON formatted SBOM support to uv export, which we encourage over the pip compatibility layer for users who are already using uv lockfiles 🙂

  14. SuryanshSS1011 commented on Jun 4, 2026

    @SuryanshSS1011

    Hi, I am interested in implementing this. Before I send a PR I want to confirm the right form-factor, since I see #10886 was closed and the discussion in the thread has shifted.

    My read of the current state is that:

    • uv export --format cyclonedx/spdx (PR Add SBOM export support #16523) is now the canonical SBOM path for lockfile-aware users.
    • pip tree --format json would still serve users who are not on uv lockfiles and want a tree-shaped graph (e.g., the Mermaid use case in the original issue).
    • The design tension @zanieb raised (pip list vs pip tree overlap, future uv list) applies to the format flag too.

    And the two questions I have are:

    1. Is pip tree --format json still a wanted addition, or has uv export superseded the use case enough that this should be closed
    2. If wanted, should the JSON shape be nested (preserving the tree, matching pipdeptree --json) or flat with requires/required-by edges (matching what tjni proposed in Print dependencies in uv pip list. #10886)?

    Happy to implement once the form-factor is settled. Thanks!

  15. zsol commented on Jun 4, 2026

    @zsol
    Member

    I don't really think we should spend time on this, given the existence of uv export (for lockfile users), and the relative lack of interest (upvotes) on the issue in the past two years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clihelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions