Skip to main content

Python dependency insight

org.openrewrite.python.migrate.DependencyInsight

Find Python dependencies, including transitive dependencies, matching a package name pattern. Results include the resolved version, scope, and whether the dependency is direct or transitive.

Recipe source

This recipe is only available to users of Moderne.

This recipe is available under the Moderne Proprietary License.

Options

TypeNameDescriptionExample
StringpackagePatternA glob pattern to match against package names. Package names are normalized per PEP 503 before matching (lowercased, runs of dashes/underscores/dots collapsed to a single dash).requests
StringscopeOptional. Filter dependencies by scope. Common scopes: main, build, or the name of an optional-dependency extra or dependency-group (e.g., dev, test). When omitted, all scopes are searched.main

Example

Parameters
ParameterValue
packagePatternrequests
scopenull
Before
pyproject.toml
[project]
name = "my-project"
dependencies = [
"requests>=2.28",
]
After
pyproject.toml
~~(requests)~~>[project]
name = "my-project"
dependencies = [
"requests>=2.28",
]

Usage

This recipe has required configuration parameters and can only be run by users of Moderne. To run this recipe, you will need to provide the Moderne CLI run command with the required options. Or, if you'd like to create a declarative recipe, please see the below example of a rewrite.yml file:

rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.DependencyInsightExample
displayName: Python dependency insight example
recipeList:
- org.openrewrite.python.migrate.DependencyInsight:
packagePattern: requests
scope: main

You will need to have configured the Moderne CLI on your machine before you can run the following command.

shell
mod run . --recipe DependencyInsight --recipe-option "packagePattern=requests" --recipe-option "scope=main"

If the recipe is not available locally, then you can install it using:

mod config recipes jar install org.openrewrite.recipe:rewrite-migrate-python:0.3.0

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Data Tables

Python dependencies in use

org.openrewrite.python.table.PythonDependenciesInUse

Direct and transitive dependencies in use in Python projects.

Column NameDescription
Project nameThe name of the project that contains the dependency (from pyproject.toml).
Project pathThe path to the project.
Package nameThe name of the Python package.
VersionThe resolved version of the package.
Version constraintThe version constraint as declared in pyproject.toml.
ScopeDependency scope: dependencies, buildRequires, optionalDependencies, or dependencyGroups.
DirectWhether this is a direct dependency (true) or transitive dependency (false).
CountHow many times this dependency appears in the dependency tree.
LicenseThe SPDX license identifier of the project, if available.