Skip to main content

A tool to analyze and clean unused Python dependencies

Project description

PDC (python-dependency-cleaner)

PDC Logo

PDC is a Python library and CLI tool that helps you analyze your Python projects to detect:

  • ✅ Used dependencies
  • ⚠️ Unused dependencies
  • 📦 Package sizes
  • 📊 Top-N largest packages

It also supports exporting reports in JSON and CSV formats.

✨ Features

  • 🔍 Static analysis of imports using AST
  • ⚡ Optional runtime import tracing
  • 📑 Detect unused packages listed in requirements.txt
  • 📦 Measure installed package sizes
  • 📊 Export reports to JSON/CSV
  • 🖥️ CLI support for quick usage
  • 📈 Show top-N largest packages for optimization

📦 Installation

Install via pip (project name is python-dependency-cleaner):

Usage

As a library

from pdc import analyze_dependencies, export_json, export_csv, top_n_packages, print_packages

    # Analyze a project
    in_use, unused = analyze_dependencies(".")

    # print in_use
    print_packages(in_use, title="✅ In-Use Packages")

    # print unused
    print_packages(unused, title="⚠️ Unused Packages")

    # Export reports
    export_json(in_use, unused, filename="report.json")
    export_csv(in_use, unused, filename="report.csv")

    # Get top n largest packages
    n = 5
    top_packages = top_n_packages(in_use, unused, n)
    print_packages(top_packages, title=f"Top {n} largest packages:")

CLI Usage

# Analyze current directory
pdc .

# Export JSON report
pdc . --json

# Export CSV report
pdc . --csv

# Show top 10 largest packages
pdc . --top 10

Requirements

  • Python 3.10+
  • Optional: packages in your requirements.txt

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

License

This project is licensed under the MIT License. See LICENSE for details.

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

python_dependency_cleaner-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

python_dependency_cleaner-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file python_dependency_cleaner-0.1.0.tar.gz.

File metadata

File hashes

Hashes for python_dependency_cleaner-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fec86183936e499e6d49b0cf3a3441a6fdd889a4c0e2ec5903d462d51709f7b3
MD5 4ea3d648ab3e84d32ef4c64e44a1cb15
BLAKE2b-256 a9a4cf90dcbbafd0880603f3e18d84c387ccfc778aadb7881e75f8ade14da662

See more details on using hashes here.

File details

Details for the file python_dependency_cleaner-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_dependency_cleaner-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9a1dbe44aafbddb0989b2b036a33539adb0d39effa7232440d5d8a9d3458d8a
MD5 c00051fd10acff5ab0b97fd5bb5c410f
BLAKE2b-256 ffd5b27220488a010e632382a3623766942e89f038ac9071428f2d2fc1b3f6f1

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