Skip to main content

A fast Python dependency analyzer that automatically discovers and extracts third-party imports

Project description

depfinder 🔍

A Python dependency analyzer inspired by Black's implementation that automatically discovers and extracts third-party imports from your Python projects. It scans your codebase to identify external dependencies while filtering out project-internal imports.

Features ✨

  • Follows Black's approach to traverse Python files
  • Smart package name resolution (e.g., PILpillow, cv2opencv-python)
  • Filters out both standard library and project-internal imports
  • Handles common import name mismatches
  • Generates requirements.txt file
  • Parallel processing for faster scanning

⚠️ Note: The tool may occasionally fail to identify some dependencies due to complex import patterns or dynamic imports.

Installation 📦

pip install depfinder

Usage 🚀

You can use depfinder either as a module or directly as a command (like Black):

# As a command (recommended)
definder src/
definder .                    # Current directory
definder src/ tests/         # Multiple paths

# As a module
python -m definder src/
python -m definder .

Options:

definder src/ --no-save     # Don't generate requirements file
definder src/ --workers 4   # Specify number of parallel workers

How it Works 🛠️

  1. Traverses Python files using Black's file discovery approach
  2. Uses AST parsing to safely extract imports
  3. Filters out standard library and project-internal imports
  4. Maps common import aliases to their correct PyPI package names
  5. Generates a clean requirements file

Output 📝

The tool will:

  1. Show all scanned files
  2. List discovered third-party dependencies
  3. Generate a requirements.txt file (or requirements-definder.txt if the former exists)

Known Limitations 🚧

  • May not detect dependencies from dynamic imports
  • Some complex import patterns might be missed
  • Package name mapping might not cover all cases

Contributing 🤝

Found a bug or want to improve the package name mapping? Contributions are welcome! Please feel free to submit a Pull Request.

License 📄

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

definder-0.1.2.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

definder-0.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file definder-0.1.2.tar.gz.

File metadata

  • Download URL: definder-0.1.2.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for definder-0.1.2.tar.gz
Algorithm Hash digest
SHA256 48f4e59611a9c61886c1367c7e0696ea211daa386896481ac9b1392decf1c5eb
MD5 f1e9a781c2f6d247acd056125f99b88b
BLAKE2b-256 48e4fc246d1620fc2b431fc435051189f80a554931d18806e4887d6c52aedd62

See more details on using hashes here.

File details

Details for the file definder-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: definder-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for definder-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a0dffa4d5c3dcbf9cd7dc7eda8810eb4c65a50edc089d55ecca11fb59a961d77
MD5 d2b12b51ce9fc37ab65bc9eb439f1fe0
BLAKE2b-256 44cc65404cc092886c3c6898b9f71c9982e421690f03cf5a29a736d043b45f5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page