Skip to main content

gpt-workflow for Python

gpt-workflow is a synchronous, typed Python wrapper around the deterministic gpt-workflow CLI. It blocks until each command finishes, captures the CLI's NDJSON and diagnostics, and does not print or retry work automatically.

Prerequisites

  • Python 3.12 or newer
  • Bun 1.3 or newer
  • an authenticated Codex CLI for workflows that call agents

The Python and npm distributions have synchronized versions.

Install the Python package after it is published:

python -m pip install gpt-workflow

Run and inspect workflows

Set gpt_workflow.cwd once to the repository that owns the workflow. It must be a pathlib.Path; relative script paths and durable run storage are resolved from it.

from pathlib import Path

import gpt_workflow

gpt_workflow.cwd = Path("/absolute/path/to/repository")

execution = gpt_workflow.run(
    ".codex/workflows/summarize.js",
    {"topic": "deterministic orchestration"},
    default_model="your-codex-model",
)

print(execution.result)
print(execution.status.run_id)
print(execution.run_directory)

for summary in gpt_workflow.runs():
    print(summary.run_id, summary.status)

status = gpt_workflow.status(execution.status.run_id)
available_models = gpt_workflow.models()

Omitting the second argument leaves workflow args undefined. Passing None sends explicit JSON null. WorkflowResult contains the JSON result, detailed WorkflowStatus, and durable run directory. runs() returns lightweight summaries; status() loads detailed phase, agent, token, failure, and fallback journal state; models() returns unique canonical model names in CLI order. Unknown compatible JSON fields are retained in each value's extra mapping. The CLI stores runs beneath $CODEX_HOME/projects/<encoded-cwd>/workflows/<workflow-name>/runs/, using gpt_workflow.cwd as the project identity; CODEX_HOME defaults to ~/.codex.

This no-agent workflow is deterministic and spends no model tokens:

export const meta = {
  name: "python-smoke",
  description: "Python SDK smoke test",
};
return { answer: 42 };

Errors and interruption

Configuration and validation fail before work starts with idiomatic exceptions: WorkflowDirectoryUnset, FileNotFoundError, TypeError, ValueError, BunError, or CLIProtocolError. Once a trustworthy run exists, failures use WorkflowError subclasses whose status and run_directory are always set. These distinguish invalid workflows and arguments, unavailable models, Codex App Server failures, budgets and limits, Git failures, JSON boundaries, cancellation, and unclassified workflow execution.

Ctrl-C before run.started remains an ordinary KeyboardInterrupt. After the run starts, the wrapper forwards SIGINT, gives the CLI a bounded opportunity to flush persisted failure state, then raises WorkflowInterrupted. That exception is also a KeyboardInterrupt and carries status and run_directory.

v1 scope

This release intentionally keeps Bun as a system prerequisite and exposes only synchronous APIs. CI, PyPI publication, bundled Bun support such as a gpt-workflow[bun] extra, and async APIs are deferred to later work.

Metadata

Release files for gpt-workflow 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 gpt-workflow 0.4.1
File Size Uploaded
gpt_workflow-0.4.1.tar.gz 40.0 kB Details

Built distribution (wheel)

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

Total release size: 52.0 kB

Release files / gpt_workflow-0.4.1.tar.gz

Download URL gpt_workflow-0.4.1.tar.gz
Size 40.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d829e4331c8c69e0ba3df4ec3f8b9057a642bf015409082745f277c4695a3401
BLAKE2b-256 checksum
How to use checksums
185b50b737c4e93359d6ca62923db7badd9862a0ac486ed6812151d55b60a62c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

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

Download URL gpt_workflow-0.4.1-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e50baa7f04a5cfa26855f61b01368424bb33ea2ca7bbf9e91e9d728003de8605
BLAKE2b-256 checksum
How to use checksums
1347b6f5c4a1d8697de89a77f01b56e8ba03b23c3fb2d49e9386b898c2561e6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.4

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