Skip to main content

A utility to analyze a Python project and its virtual environment to identify unused direct dependencies. Helps you keep your dependency list lean and accurate.

Project description

direct-deps

PyPI - Version PyPI - Python Version pre-commit.ci status


Table of Contents

Introduction

A utility to analyze a Python project and its virtual environment to identify direct dependencies. Helps you keep your dependency list lean and accurate.

The tool automatically detects common virtual environment setups including:

  • Current activated virtual environment ($VIRTUAL_ENV)
  • Local .venv or venv directories
  • Hatch environments
  • Pipenv environments

Installation

Installation is optional! You can run direct-deps without installing it using uvx or pipx run.

# Optional: Install globally
pipx install direct-deps

# or
uv tool install direct-deps

Usage

direct-deps exposes three subcommands — check, extract-imports, and find-package. The recommended way to run any of them is without installation via uvx or pipx run. Every command accepts one or more files or directories (directories are scanned recursively).

check (primary)

The main command: it lists your project's direct dependencies. Run it directly without installation — the tool will automatically detect your project's virtual environment:

# Using uvx (uv's tool runner)
uvx direct-deps check .

# Using pipx
pipx run direct-deps check .

# Or analyze specific directories
uvx direct-deps check src
uvx direct-deps check tests

To split packages and dev-packages you can do the following.

# Sample Project Structure
├── pyproject.toml
├── src
│   └── comma-cli
│       └── ...
└── tests
    └── ...
$ uvx direct-deps check src
persistent-cache-decorator
requests
rich
setuptools-scm
typedfzf
typer

$ uvx direct-deps check tests
pytest
runtool
tomlkit
typer

# So my [project.dependencies] would be:
[project]
dependencies = [
  "persistent-cache-decorator",
  "requests",
  "rich",
  "setuptools-scm",
  "typedfzf",
  "typer",
]

# And my [project.optional-dependencies.dev] would be (notice that since typer is a main dependency, there is no need to list it here):
[project.optional-dependencies]
dev = [
  "pytest",
  "runtool",
  "tomlkit",
]

extract-imports

Lists every unique top-level import found in the given files or directories. This is the raw input that check resolves against your environment, so it's useful for debugging what the tool actually detected. Standard-library modules are excluded by default (pass --include-builtin to include them, and --include-jupyter to scan notebooks).

$ uvx direct-deps extract-imports src
persistent_cache_decorator
requests
rich
typedfzf
typer

find-package

Resolves one or more import/module names to the distribution (package) names that provide them, using your environment's metadata. Handy when an import name differs from its PyPI package name (e.g. yaml is provided by PyYAML).

$ uvx direct-deps find-package yaml requests
PyYAML
requests

Limitations

This tool relies on being able to look at the import <package> and from <package> import ... as well as use your virtualenv to find the appropriate package name. This means that anything not imported directly will not appear in the list such as plugins (pytest-cov) and static analysis tools (ruff, pre-commit).

License

direct-deps is distributed under the terms of the MIT license.

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

direct_deps-0.0.5.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

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

direct_deps-0.0.5-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file direct_deps-0.0.5.tar.gz.

File metadata

  • Download URL: direct_deps-0.0.5.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for direct_deps-0.0.5.tar.gz
Algorithm Hash digest
SHA256 abe87c285c6d107c07b077050cd4b3a992b0e5a4d8fc82761790c08c9f18fff1
MD5 d1ef58396f56791e8299ffd78fe201b7
BLAKE2b-256 4c1bac4cd31dc84d2cd7413656960b0a992646b565f4b0e18972d2b34df455f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for direct_deps-0.0.5.tar.gz:

Publisher: main.yaml on FlavioAmurrioCS/direct-deps

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file direct_deps-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: direct_deps-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for direct_deps-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b3bd2b509775877e68c9b0e52a38c0684b1934ea0727178559366da6e49efac7
MD5 8b32510be597068ad4aeb16a22da17ac
BLAKE2b-256 46ea3bb155fc64a4158f754b1dc188f8031524a6c886ddcfee633726ec57ad2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for direct_deps-0.0.5-py3-none-any.whl:

Publisher: main.yaml on FlavioAmurrioCS/direct-deps

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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