Skip to main content

Subfork Python

The Python client for Subfork. Discover nodes, build reusable graphs, publish versions, and run them from your scripts, applications, or agents.

Install

Requires Python 3.8+.

pip install subfork

Connect

Create a key under Account → API keys in Subfork and set SUBFORK_API_KEY in your environment. Grant the permissions your application needs: read, write, run, and/or publish. Keep the key out of source files and graph definitions.

from subfork import Subfork

with Subfork() as client:
    nodes = client.nodes.list()
    graphs = client.graphs.list()

The client reads SUBFORK_API_KEY and connects to subfork.com.

Command line

The package includes a subfork CLI that uses your SUBFORK_API_KEY.

subfork list
subfork export GRAPH_ID --output graph.json
subfork validate graph.json
subfork create graph.json --name "My new graph"
subfork publish GRAPH_ID --version v1
subfork execute GRAPH_ID --version v1
subfork execute GRAPH_ID -o results.json

execute waits for completion and returns JSON. Use -o to save results to a file; progress stays on stderr. Add -f / --force to overwrite existing output files with execute or export. Run subfork --help or subfork execute --help for more options.

Create and run a graph

This example creates a text-producing graph, publishes v1, and runs that version. It requires read, write, publish, and run permissions. Graphs are public, and runs use your account's execution quota.

from subfork import Subfork

name = "Python greeting"
definition = {
    "name": name,
    "nodes": [{
        "node_instance_id": "hello",
        "node_id": "n_text_value",
        "node_version": "1.0.0",
        "title": "Hello",
        "params": {"text": "Hello from Python"},
    }],
    "edges": [],
    "graph_outputs": {
        "text": {"node_instance_id": "hello", "output_name": "text"},
    },
}

with Subfork() as client:
    client.graphs.validate(definition)
    graph = client.graphs.create(name=name, definition=definition)
    client.graphs.publish(graph["id"], version="v1")

    execution = client.graphs.execute(graph["id"], version="v1")
    result = client.executions.wait(execution["id"], timeout=120)
    print(result["status"], result.get("outputs"))

To test a draft before publishing, call graphs.execute(graph_id) without a version. To update a draft, use graphs.update() with its name, definition, and description; omitting the description clears it.

Reuse building blocks

Explore published graphs and inspect their versioned interfaces:

with Subfork() as client:
    blocks = client.graphs.published()
    block = client.graphs.published_version(graph_id, "v1")

Replace graph_id with the ID of a graph you want to use. Published graph versions can be composed into larger graphs using the returned composite node manifest. Pin child versions so later publications do not change your graph's behavior.

Handle failures

HTTP failures raise APIError subclasses, including AuthenticationError, PermissionDeniedError, ValidationError, and RateLimitError. These expose status_code and an optional retry_after header.

executions.wait() returns failed and canceled runs as well as successful ones, so check the returned status. An ExecutionTimeout stops polling but does not cancel the remote run; use executions.cancel(execution_id) to request cancellation.

The client does not automatically retry requests. After a TransportError, check remote state before repeating a create, publish, or execute request.

Documentation

See the documentation for installation, Python usage, CLI options, and examples. Browse Subfork Examples and the subfork-examples repository for graphs to learn from and reuse.

Contributing

See CONTRIBUTING.md for development and code-quality checks.

License

BSD-3-Clause.

Metadata

Release files for subfork 2.0.0

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

Source distribution (sdist)

Source distribution for subfork 2.0.0
File Size Uploaded
subfork-2.0.0.tar.gz 24.9 kB Details

Built distribution (wheel)

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

Total release size: 41.6 kB

Release files / subfork-2.0.0.tar.gz

Download URL subfork-2.0.0.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
673d45f42162f593e735fa7fb50a8e3e5a91283f0ab2513c2ba7cb46601df3f0
BLAKE2b-256 checksum
How to use checksums
83f498aff6b36ffdf32f70e8956dc127c836b5c53000725751d1565e1ed6e2f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / subfork-2.0.0-py3-none-any.whl

Download URL subfork-2.0.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7f89f72aac7a7892dbb659ce0df0d698f7b127aa1e9b7f1f0c2a6d8c4a5b561
BLAKE2b-256 checksum
How to use checksums
d1c5ba156db7c4e9bdb0c51e6691855f0375af06c5bee58c9839cccb60466bf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release history Release notifications | RSS feed

2.0.2

2 release files

2.0.1

2 release files

This release

2.0.0 This release

2 release files

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.9.17

1 release file

0.9.16

1 release file

0.9.15

1 release file

0.9.14

1 release file

0.9.13

1 release file

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