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):

🔗 PyPI: python-dependency-cleaner
🔗 Github: python-dependency-cleaner

pip install python-dependency-cleaner==0.1.1

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.1.tar.gz (8.5 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.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for python_dependency_cleaner-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3eb37d631ee7b075c4e4900e95a46625f062a98cd53a8eda15745de1979c9bd2
MD5 527665a42fd6204fa24c682076c97750
BLAKE2b-256 1ec245acd8f07333432946ea521f205c7a6117b4bb276cd0e27e1e1f79b08b8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dependency_cleaner-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8c5f40a89f0dfd14c50a198d20bee715b6246177b1351facc5626c739516177
MD5 2fc18007d2259900ac1de605677febca
BLAKE2b-256 84d82f207c1f26d0039bac312b2553a330077be580e5d42eea08651c7a27c3fe

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