Home ยป Finding Python package dependencies

Finding Python package dependencies

  • by
  • 2 min read

This a brief overview on how to find the dependencies of a Python package. You might need this in case you have to upload packages to a custom package repository or conda channel. Let’s dive in.

Find package dependencies with PyPi JSON endpoint

To find a Python package’s dependencies, you can parse a package’s PyPi JSON endpoint. These endpoints can be found at:


You can parse the JSON at this URL with the requests package, as follows:

package_json = requests.get('https://pypi.org/pypi/seaborn/0.11.2/json', verify = False).json()

If you run this for the Seaborn package, you’ll get: [‘numpy (>=1.15)’, ‘scipy (>=1.0)’, ‘pandas (>=0.23)’, ‘matplotlib (>=2.2)’]

But there’s an issue here. Some of Seaborn’s dependencies have dependencies themselves. They aren’t listed here. Luckily, there is a solution. Read on!

Find package dependencies with Pipdeptree

If you want to find all (including nested) dependencies: use pipdeptree, which is a command-line tool with many options for listing and visualizing dependencies.

pip install pipdeptree

Runnin the pipdeptree command in your terminal will print all of your packages’ dependencies. In the example below, I took a snapshot from my pipdeptree output and show what Seaborn’s dependencies look like.

  - matplotlib [required: >=2.2, installed: 3.5.1]
    - cycler [required: >=0.10, installed: 0.11.0]
    - fonttools [required: >=4.22.0, installed: 4.31.2]
    - kiwisolver [required: >=1.0.1, installed: 1.4.1]
    - numpy [required: >=1.17, installed: 1.22.3]
    - packaging [required: >=20.0, installed: 21.3]
      - pyparsing [required: >=2.0.2,!=3.0.5, installed: 3.0.7]
    - pillow [required: >=6.2.0, installed: 9.0.1]
    - pyparsing [required: >=2.2.1, installed: 3.0.7]
    - python-dateutil [required: >=2.7, installed: 2.8.2]
      - six [required: >=1.5, installed: 1.16.0]
  - numpy [required: >=1.15, installed: 1.22.3]
  - pandas [required: >=0.23, installed: 1.4.1]
    - numpy [required: >=1.21.0, installed: 1.22.3]
    - python-dateutil [required: >=2.8.1, installed: 2.8.2]
      - six [required: >=1.5, installed: 1.16.0]
    - pytz [required: >=2020.1, installed: 2022.1]
  - scipy [required: >=1.0, installed: 1.8.0]
    - numpy [required: >=1.17.3,<1.25.0, installed: 1.22.3]

If you want to get pipdeptree’s output in a text file, use:

pipdeptree >> dependencies.txt

Congratulations, you can now find the dependencies of Python packages.

Leave a Reply

Your email address will not be published.