Skip to main content

GitHub release (latest by date) PyPI GitHub Release Date GitHub last commit (branch) GitHub Workflow Status GitHub

dyn2py

Extract python code from Dynamo graphs

Use cases:

  • Track changes in python nodes in source control systems like git
  • Work on python code in your favorite code editor outside Dynamo. dyn2py can also update Dynamo graphs from previously exported python files.

Installation

Windows portable and installer

Prebuilt portable exe and installer available from github releases.

No requirements, just download dyn2py.exe or dyn2py-installer.exe from release assets:

https://github.com/infeeeee/dyn2py/releases/latest

Installer automatically adds the install folder to the path, so simply dyn2py can be called from anywhere.

With pip

For usage as a module or as a command line program

Requirements: python, pip

pip install dyn2py

Usage

As a standalone command line program

> dyn2py --help
usage: dyn2py [-h] [-v] [-l LOGLEVEL] [-n] [-F] [-b] [-f {py,dyn}] [-u] [-p path/to/folder] [source ...]

Extract python code from Dynamo graphs

positional arguments:
  source                path to a Dynamo graph, a python script or a folder containing them

options:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -l LOGLEVEL, --loglevel LOGLEVEL
                        set log level, possible options: HEADLESS, CRITICAL, ERROR, WARNING, INFO, DEBUG
  -n, --dry-run         do not modify files, only show log
  -F, --force           overwrite even if the files are older
  -b, --backup          create a backup for updated files
  -f {py,dyn}, --filter {py,dyn}
                        only check python or Dynamo graphs, skip the others, useful for folders

dynamo options, only for processing Dynamo graphs:
  -u, --update          update Dynamo graph from python scripts in the same folder
  -p path/to/folder, --python-folder path/to/folder
                        extract python scripts to this folder, read python scripts from here with --update

The script by default overwrites older files with newer files.
Do not move the source Dynamo graphs, or update won't work with them later.
Multiple sources are supported, separate them by spaces.
HEADLESS loglevel only prints modified filenames.

Examples

Notes: In Windows cmd use backward slashes as path separators, in any other shells use forward slashes. Powershell accepts both of them. Wrap paths with spaces in double quotes.

# Extract all nodes next to a Dynamo file:
dyn2py path/to/dynamofile.dyn

# Update a Dynamo file from previously exported and modified python files:
dyn2py --update path/to/dynamofile.dyn

# Extract python nodes to a specific folder, process multiple Dynamo files:
dyn2py --python-folder path/to/pythonfiles path/to/dynamofile1.dyn path/to/dynamofile2.dyn

# Update Dynamo files from python files from a folder. Only check python files, create backups:
dyn2py --filter py --backup path/to/pythonfiles

Git hooks

Git hooks are a built-in feature of Git that allow developers to automate tasks throughout the Git workflow. Read more here: https://githooks.com/

With the pre-commit hook it's possible to add more files to the currently initialized commit.

You can find an example pre-commit hook here: pre-commit. Copy this file to the .git/hooks folder of your repo of Dynamo graphs. This folder is hidden by default, but it should exist in all initialized git repo. Do not rename this file.

This script will go through staged .dyn files and export python scripts from them, and add them to the current commit. Now you can check changed lines in a diff tool, you can see changed python code in a PR!

As a python module

Full API documentation available here: https://infeeeee.github.io/dyn2py

Examples

Extract all nodes from python nodes next to a Dynamo file:

import dyn2py

# Open a Dynamo graph:
dynamo_file = dyn2py.DynamoFile("path/to/dynamofile.dyn")

# Extract python nodes:
dynamo_file.extract_python()

# Save all python nodes as separate files:
dyn2py.PythonFile.write_open_files()

Update python node from a python file:

import dyn2py

# Open a python file:
python_file = dyn2py.PythonFile("path/to/pythonfile.py")

# Update the node in the graph:
python_file.update_dynamo()

# Save modified Dynamo graph:
dyn2py.DynamoFile.write_open_files()

Update all python nodes of a Dynamo grapg from a different folder, save backups:

import dyn2py

# open a Dynamo graph:
dynamo_file = dyn2py.DynamoFile("path/to/dynamofile.dyn")

# Get python files from a dofferent folder:
python_files = dynamo_file.get_related_python_files(python_folder="path/to/pythonfiles")

# Read python files and update the graph:
[python_file.update_dynamo() for python_file in python_files]

# Save open Dynamo graphs:
dyn2py.DynamoFile.write_open_files(backup=True)

For more examples check tests in the tests folder on Github

They should work in Dynamo, inside CPython3 nodes.

Troubleshooting

If you have a problem, open an issue on Github

You can also ask about this project on Dynamo Forum, don't forget to ping me: @infeeeee

Limitations

Only supports Dynamo 2 files, Dynamo 1 files are reported and ignored. Please update them to Dynamo 2 by opening them in Dynamo 2.

Both IronPython2 and CPython3 nodes are supported! IronPython2 nodes won't be updated to CPython3, they will be imported as-is.

Cannot create new python nodes, only existing ones can be updated.

Development

Installation

Requirements: git, python, pip

git clone https://github.com/infeeeee/dyn2py
cd dyn2py
pip install -e .

With venv:

git clone https://github.com/infeeeee/dyn2py
cd dyn2py
python -m venv .venv
. ./.venv/bin/activate
pip install -e .

Build for Windows

pip install -e .[build]
pyinstaller dyn2py.spec

Create installer for Windows

Live module documentation

pip install -e .[doc]
pdoc -d google dyn2py

Unit tests

VSCode should automatically discover unit tests.

To run them manually:

python -m unittest discover -v -s ./tests -p "test_*.py"

New release

  1. Update version number in pyproject.toml
  2. Create and publish a git tag with that number

License

GPL-3.0

Metadata

Release files for dyn2py 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dyn2py 0.4.1
File Size Uploaded
dyn2py-0.4.1.tar.gz 56.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dyn2py 0.4.1
File Interpreter ABI Platform
dyn2py-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 94.8 kB

Release files / dyn2py-0.4.1.tar.gz

Download URL dyn2py-0.4.1.tar.gz
Size 56.2 kB
Tags Source
SHA-256 checksum
How to use checksums
54a699002dd5a9ecf332665c442203066dd5bec9a23563a7d32fc005c1554fe9
BLAKE2b-256 checksum
How to use checksums
e31f8dec639e120012d1ef4ccd56d5741c4a84eb585d924c7e71cbc82aec1dd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / dyn2py-0.4.1-py3-none-any.whl

Download URL dyn2py-0.4.1-py3-none-any.whl
Size 38.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7aaf035b86fd63a7cbaa104c5aea88cbd02e9802269090be4f49b2110923cce9
BLAKE2b-256 checksum
How to use checksums
c25d44733141059b5f044a3db2984a0665b44b56c000229a8b9d1bf7c0adedfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page