Skip to content

Extract top-level import names from PyPI without requiring local installation #1136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
m-aciek opened this issue May 2, 2025 · 0 comments · May be fixed by #1137
Open

Extract top-level import names from PyPI without requiring local installation #1136

m-aciek opened this issue May 2, 2025 · 0 comments · May be fixed by #1137
Labels
enhancement New feature or request

Comments

@m-aciek
Copy link

m-aciek commented May 2, 2025

Is your feature request related to a problem? Please describe.

Currently, deptry relies on the presence of installed packages in the runtime environment to map declared dependencies to top-level imports. While this avoids installing packages explicitly, it still requires them to be available locally.

Describe the solution you would like

I'd like to suggest an enhancement: allow deptry to extract top-level import names directly from PyPI, without needing the package to be installed. This could be done by querying the PyPI JSON API, downloading the .whl file for a given distribution, and reading the top_level.txt file from its .dist-info directory.

This would enable:

  • Analysis of projects in clean or containerized environments,
  • Easier integration with CI pipelines where dependency installation is undesired,
  • Potential fallback behavior when a dependency is declared but not installed.

Additional context

The top-level imports can be found in top_level.txt within .dist-info inside .whl files hosted on PyPI. This could serve as a lightweight and deterministic way to get the needed information without installing or importing anything.

This idea could also complement or even help automate the package-module-name-map feature, by providing a way to infer unknown mappings programmatically when they’re not explicitly configured.

The mapping would be based on the latest version of each package on PyPI, which should generally be safe, as top-level import names tend to be stable and rarely change across versions.

Would you be open to exploring this as an optional mode or fallback? I’d be happy to contribute ideas or code if this aligns with the project’s direction.

@m-aciek m-aciek added the enhancement New feature or request label May 2, 2025
@m-aciek m-aciek linked a pull request May 2, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant