What tools can I use to build a list of direct dependencies from a Python project?

Viewed 40

Note that I'm not talking about pip, which hinges on me specifying the dependencies. Rather, what tools could analyze code any give me that initial pip file?

I also don't want something like a lock file, that mingles direct and indirect dependencies. That's useful for deployment, but my purpose here is really to analyze dependency files and figure out what projects are specifying but not using.

1 Answers

I don't know of an existing library, but you could parse all the from ____ import ____ and your import ____ lines in your code and put them through a translation of {"base_module_name", "library_name"} to see and count usages of each one.

example translator:

{
  "redis": "redis",
  "requests": "requests",
  "sentry_sdk": "sentry",
  ...
}
Related