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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpt_workflow-0.4.0.tar.gz (40.0 kB view details)

Uploaded Source

Built Distribution

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

gpt_workflow-0.4.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file gpt_workflow-0.4.0.tar.gz.

File metadata

  • Download URL: gpt_workflow-0.4.0.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for gpt_workflow-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8d79b5ea7da788193ff3da6b3e959c5bcbf530b5f2a7551c2c9180f4ac91b08b
MD5 0264ead547ef40614e9a94d0116261ba
BLAKE2b-256 657e663de228d63c302149f3f29af59c3bf378c6cffc7ef2a14403b3218ff415

See more details on using hashes here.

File details

Details for the file gpt_workflow-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: gpt_workflow-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for gpt_workflow-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68a3585db0c8f6d09bdba1e5642956007ddc868540935b064899ce82131cd71f
MD5 3f032d00923604ede3a1343ca2b5c678
BLAKE2b-256 49ebe62a0399da18d60ddaee7c147a6c650b4a9e62ef93341bbfa96f5b6da6c6

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 Sentry Error logging StatusPage Status page