List dependencies of the Python libraries in your project

There’s an interesting library available, that lists s. We’ll cover just the basics here, but I encourage you to explore it in more more depth on your own.

The johnnydep library

You can simply install it with pip install johnnydep.

Then, if you want to get the list of dependencies of latest version of i.e Django library, you can call it with:

1
johnnydep Django

and it will output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
2022-10-29 19:15:46 [info    ] init johnnydist           [johnnydep.lib]
2022-10-29 19:15:50 [info    ] init johnnydist           [johnnydep.lib]
2022-10-29 19:15:51 [info    ] init johnnydist           [johnnydep.lib]
2022-10-29 19:15:52 [info    ] init johnnydist           [johnnydep.lib]
name                 summary
-------------------  ------------------------------------------------------
Django               A high-level Python web framework that e
├── asgiref<4,>=3.5.2  ASGI specs, helper code, and adapters
├── backports.zoneinfo Backport of the standard library zoneinfo
└── sqlparse>=0.2.2    A non-validating SQL parser.

Or you can specify the library’s version as well:

1
johnnydep Django==4.0.3

and it will list the dependencies for that version:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
2022-10-29 19:16:55 [info    ] init johnnydist           [johnnydep.lib]
2022-10-29 19:16:56 [info    ] init johnnydist           [johnnydep.lib]
2022-10-29 19:16:57 [info    ] init johnnydist           [johnnydep.lib]
2022-10-29 19:16:58 [info    ] init johnnydist           [johnnydep.lib]
name                 summary
-------------------  ------------------------------------------------------
Django==4.0.3        A high-level Python web framework that e
├── asgiref<4,>=3.4.1  ASGI specs, helper code, and adapters
├── backports.zoneinfo Backport of the standard library zoneinfo
└── sqlparse>=0.2.2    A non-validating SQL parser.

List dependencies of all libraries in your project

Let’s first activate the virtualenv or your project:

1
2
cd your/project/folder/
source <venv_name>/bin/activate

List dependencies of installed version of each library

Ok. Now, if you want to list the libraries of your entire project, you can call:

1
pip freeze | xargs -n1 johnnydep

where pip freeze lists all installed libraries with their versions (1 library per line) and the -n1 parameter of xargs command ensures that it will feed 1 line at a time to the johnnydep library. This will list the dependencies of all libraries in you project, for the versions that you use.

List dependencies of the latest version of each library

You can also list all the dependencies of the latest versions of all of the libraries from your project, by calling:

1
pip freeze | awk -F "==" '{print $1}' | xargs -n1 johnnydep

The awk -F "==" '{print $1}' will split the e.g. Django==4.0.3 into Django and 4.0.3 and will pass only the first value to the johnnydep library.