Skip to main content

Convert Python function plans to DAG (JSON, pseudo, optional SVG).

Project description

py2dag

Convert Python function plans to a DAG (JSON, pseudo, optional SVG).

Install

  • From PyPI (once published):
pip install py2dag
  • From source using Makefile targets (recommended for development):
make setup         # create .venv and install deps (SVG extra by default)

Dev Environment via Makefile

  • Install Poetry (see poetry docs or pipx install poetry).
  • From the repo root:
poetry install

Notes:

  • HTML export uses Dagre via CDN (d3.js + dagre-d3). No local system deps, but an internet connection is required when opening plan.html. If you are offline or behind a firewall, the page will show a message; vendor the JS locally or open with internet access.
  • Optional Graphviz SVG export (--svg) requires Graphviz system binaries (e.g., brew install graphviz).

Local Virtualenv (.venv)

  • Create/update venv and install deps: make setup
  • Open interactive shell inside venv: make shell
  • .venv/ is ignored by git.

Usage

  • Run via Makefile (dev) — generates an interactive Dagre HTML graph:
make run FILE=path/to/your_file.py ARGS=--html
  • Run the installed CLI (after pip install py2dag):
py2dag path/to/your_file.py --html
  • Or directly with Python (inside venv):
poetry run python cli.py path/to/your_file.py --html

This generates plan.json, plan.pseudo, and if --html is used, plan.html.

  • Function name: By default the tool auto-detects a suitable function in the file. To target a specific function, pass --func NAME.

Offline HTML (no internet)

plan.html references d3 and dagre-d3 from CDNs. To view graphs fully offline, download those files and place them next to plan.html, then edit the two <script> tags in py2dag/export_dagre.py to point at your local copies.

Example (download once):

wget https://d3js.org/d3.v5.min.js -O d3.v5.min.js
wget https://unpkg.com/dagre-d3@0.6.4/dist/dagre-d3.min.js -O dagre-d3.min.js

Then update the script tags to ./d3.v5.min.js and ./dagre-d3.min.js and regenerate plan.html.

Tests

Run tests using the Makefile (prints visible with -s):

make test

Build

Build the package artifacts (wheel and sdist):

make build

Releasing to PyPI

This repo includes a GitHub Actions workflow that publishes to PyPI when you push a Git tag like v0.1.1.

  1. In GitHub repo settings, add a repository secret named PYPI_API_TOKEN with your PyPI token (format: pypi-***).

  2. Bump patch version, commit, and tag locally; then push tags to trigger the workflow:

make patch        # bumps version, commits, and tags vX.Y.Z
make release      # pushes commits and tags to GitHub (triggers publish)

Or push tags manually:

git push --tags

You can also install from the local build with pip install dist/*.whl.

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

py2dag-0.1.8.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

py2dag-0.1.8-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file py2dag-0.1.8.tar.gz.

File metadata

  • Download URL: py2dag-0.1.8.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for py2dag-0.1.8.tar.gz
Algorithm Hash digest
SHA256 10b327fb81465059958c6da3b00fbebc2fb5bd95d1ac0e4f51ea93327d29d45e
MD5 c770645594d5a93e51f73ddd4d8824ec
BLAKE2b-256 c32afaf9028f00dfb65b965dc3d74d05104d649d4d37199b727bab3536c2f227

See more details on using hashes here.

File details

Details for the file py2dag-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: py2dag-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for py2dag-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 988140f18aef92109b90874489cc17e6adf163cfc9aae40e7c37c44ee9e6e829
MD5 fa4d56c897595c27849a0e72bf7099f4
BLAKE2b-256 9b5dba10eca0c1d02d3fbf37c760fa005b5f3317366efd1c429bce03fded79c2

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