A developer utility to isolate, analyze, and compose Python code dependencies.
Project description
deph: Isolate, Analyze, and Compose Your Python Code
deph is a developer utility designed to untangle Python codebases. It traces and isolates all the necessary source code for a specific function or class (an "endpoint"), analyzes its dependencies, and then composes the code into a clean, self-contained module.
This is especially powerful for code developed in interactive environments like Jupyter Notebooks, where dependencies can be scattered and implicit. deph helps you extract a piece of logic—like a model's prediction function or a data processing pipeline—from a complex notebook or script and prepare it for refactoring, testing, or future packaging.
Key Features
- Endpoint-based Code Isolation: Pinpoint a function or class, and
dephwill recursively find all internal dependencies (other functions, classes, global variables) required for it to run. - Dependency Analysis: Automatically identifies the standard library, third-party, and local modules your isolated code depends on.
- Source Code Composition: Gathers all the required source code and assembles it into a single, clean Python module, ready for use in a new context.
- Jupyter-Aware: Works inside Jupyter Notebook/Lab by analyzing the live Python session (in-memory functions, classes, variables, and imports).
Why Use deph? (The Problem)
Imagine you have a large Jupyter Notebook used for exploratory data analysis. It contains a critical function for training a model, but its helper functions and imports are spread across dozens of cells. To move that training logic into a production pipeline, you would have to:
- Manually copy-paste the main function.
- Hunt down every helper function it calls.
- Figure out which
importstatements are actually needed. - Repeat this process until the code runs without errors.
deph automates this. It answers the question: "What is the absolute minimum code and which libraries are required to run this specific function?"
Use Cases:
- Isolating logic from a monolithic script to create a reusable module.
- Extracting a specific feature from a Jupyter Notebook to create a standalone script.
- Preparing a piece of logic to be packaged into a library or deployed as a service.
- Understanding the true dependencies of a specific part of your application.
Installation
# Core library
python -m pip install deph
# Test dependencies (used only by the test suite)
python -m pip install "deph[test]"
Quickstart
Let's say you have a Python file my_model.py containing a function train_model that you want to isolate.
# my_model.py
import pandas as pd
def preprocess(data):
return data.dropna()
def train_model(df: pd.DataFrame):
processed_df = preprocess(df)
# ... training logic ...
return "Model trained!"
You can use deph's high-level functions to isolate train_model and all its local dependencies (like preprocess):
from deph import isolate, analyze
from my_model import train_model
# 1) Analyze the target to inspect dependencies
report = analyze(train_model)
print("--- IMPORTS ---")
print(report["imports"]) # Dict by module with ImportItem entries
# 2) Isolate the target function to get the composed code result
result = isolate(train_model)
# 3) Print the results
print("--- ISOLATED SOURCE CODE ---")
print(result.source)
print("\n--- IDENTIFIED DEPENDENCIES ---")
print(report.get("imports"))
# Extras available on result:
# - result.warnings (list of unresolved names; also printed to stderr)
# - result.reqs_pypi (inferred non-stdlib PyPI packages)
# - result.reqs_unknown (non-stdlib, not resolvable on PyPI)
This will produce a self-contained script with train_model, preprocess, and the necessary import pandas as pd statement, along with a detailed dependency report.
Utilities (Optional)
deph.utils includes a few lightweight helpers used in examples:
deph.utils.log: simple console/file logging configurationdeph.utils.zip: ZIP archive helpersdeph.utils.pip: a thin wrapper aroundpip
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deph-1.1.2.tar.gz.
File metadata
- Download URL: deph-1.1.2.tar.gz
- Upload date:
- Size: 57.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a1fa82a32c0c52a84f0574386ef087ecd3ae9126ffcb4aa0274d08cef312830
|
|
| MD5 |
90c6f9c697eb1cb37546961b260e8b4c
|
|
| BLAKE2b-256 |
3d267b4038f73ca54404f268fbb491c09423007c2497fa5bbe38da5c1b5044d9
|
Provenance
The following attestation bundles were made for deph-1.1.2.tar.gz:
Publisher:
python-publish.yml on dvm-shlee/deph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deph-1.1.2.tar.gz -
Subject digest:
5a1fa82a32c0c52a84f0574386ef087ecd3ae9126ffcb4aa0274d08cef312830 - Sigstore transparency entry: 584597164
- Sigstore integration time:
-
Permalink:
dvm-shlee/deph@db61e629cd22a82447f02235a35f5a8eb6f890f2 -
Branch / Tag:
refs/tags/v1.1.2 - Owner: https://github.com/dvm-shlee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@db61e629cd22a82447f02235a35f5a8eb6f890f2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file deph-1.1.2-py3-none-any.whl.
File metadata
- Download URL: deph-1.1.2-py3-none-any.whl
- Upload date:
- Size: 54.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d3245a4a1a89df8d02196bd0eff1343a5bbdcb148441f9c656394707e6ea179
|
|
| MD5 |
2bbae7517af5c4838f335d1f825eefb5
|
|
| BLAKE2b-256 |
aae6b4f31f866ae1c45897376c35315d0f7e0872d44b6473ddf70e81b56f6aa7
|
Provenance
The following attestation bundles were made for deph-1.1.2-py3-none-any.whl:
Publisher:
python-publish.yml on dvm-shlee/deph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deph-1.1.2-py3-none-any.whl -
Subject digest:
7d3245a4a1a89df8d02196bd0eff1343a5bbdcb148441f9c656394707e6ea179 - Sigstore transparency entry: 584597165
- Sigstore integration time:
-
Permalink:
dvm-shlee/deph@db61e629cd22a82447f02235a35f5a8eb6f890f2 -
Branch / Tag:
refs/tags/v1.1.2 - Owner: https://github.com/dvm-shlee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@db61e629cd22a82447f02235a35f5a8eb6f890f2 -
Trigger Event:
release
-
Statement type: