Pipes and external processes
Dagster Pipes is a protocol for running compute outside the Dagster process while keeping the work part of a Dagster asset or operation. It carries Dagster execution context into the external process and carries logs, asset results, checks, and custom data back to Dagster.
System boundary
Dagster Pipes separates orchestration from compute without separating their execution contract. The Dagster process owns the run and the communication session. An external process owns the business work and uses a small Pipes library to connect to that session.
Orchestration side
The orchestration side creates a session from the current asset or operation context. It makes the context available to the external process and listens for messages that it turns into Dagster results and events. PipesSession is the common session object, while PipesClient is the common launch contract for environment-specific clients. python_modules/…/context.py python_modules/…/client.py
The launch environment can be a local subprocess or a managed external system. The launch client does not need to know the details of the external program's business logic. It only needs to start the process with the Pipes bootstrap data and keep the session open until the process ends.
References: python_modules/…/context.py• L263-300 python_modules/…/client.py• L27-54
External side
The external process connects near its entry point with open_dagster_pipes() from the fully qualified package python_modules/…/__init__.py. The returned PipesContext exposes the asset and partition scope for the work. It also provides the methods that send structured output back to Dagster. python_modules/…/__init__.py
The external code remains free to use its own language and compute system. The current first-party library is Python's dagster-pipes package. Its runtime package has no required third-party dependency and supports Python 3.11 through 3.14. An optional stubs extra adds Google Cloud Storage support for related type stubs. python_modules/…/pyproject.toml python_modules/…/uv.lock Integration libraries and deployment
References: python_modules/…/__init__.py• L1534-1587 python_modules/…/pyproject.toml• L5-24 python_modules/…/uv.lock• L1-8
Session lifecycle
A Pipes session covers the communication channels, external launch, message handling, and cleanup. Both sides use a context manager so that startup and close actions happen around the same unit of external work.
Bootstrap exchange
The orchestration side builds a serializable context payload from the Dagster execution context. This payload can include selected asset keys, code versions, data provenance, partition information, run identity, retry information, and user-provided extras. The context injector stores or embeds that payload. The message reader prepares the destination for messages. python_modules/…/context.py python_modules/…/utils.py
The session then exposes two bootstrap parameters. One identifies the context payload. The other identifies the message destination. The normal transport is a pair of encoded environment variables. CLI arguments are an alternative when the launch system cannot set environment variables. python_modules/…/context.py
References: python_modules/…/context.py• L481-531 python_modules/…/utils.py• L48-132 python_modules/…/context.py• L306-396
Process connection
The external process reads the bootstrap parameters through a params loader. It then loads the context and opens a message writer. On open, it sends an opened message. On close, it sends a closed message and flushes any buffered output. python_modules/…/__init__.py python_modules/…/__init__.py
The complete exchange is shown below. The launch client or custom launcher owns the process start, while the session owns the channel setup and final drain.
sequenceDiagram
participant D as Dagster process
participant E as External process
D->>D: Create context payload
D->>D: Open message reader
D->>E: Launch with bootstrap parameters
E->>E: Load context and open writer
E-->>D: opened
E-->>D: logs and structured results
E-->>D: closed
D->>D: Drain messages and clean up
References: python_modules/…/__init__.py• L546-616 python_modules/…/__init__.py• L1611-1652 python_modules/…/utils.py• L861-948
Session cleanup
open_pipes_session() keeps reading while the external process runs and drains the remaining messages after it exits. A missing opened message means the external process did not connect to the expected Pipes channel. A missing closed message warns that buffered output may not have reached Dagster. python_modules/…/utils.py
The external side should use open_dagster_pipes() as a context manager. This gives the message writer a defined close point and preserves the final event and error data. python_modules/…/__init__.py
References: python_modules/…/utils.py• L861-948 python_modules/…/__init__.py• L1628-1652
Launch APIs
Dagster exposes two levels of launch control. A PipesClient packages session setup, process launch, message reading, and completion into one resource-like API. open_pipes_session() exposes the session directly for launch systems that need custom polling or lifecycle control.
Managed launch clients
PipesClient.run() is the shared API for clients that launch compute in a specific environment. Each client accepts the Dagster execution context and optional extras, then adds the arguments needed by its environment. The result is a PipesClientCompletedInvocation that gives the caller access to reported results and custom messages. python_modules/…/client.py
The repository provides clients for common launch shapes such as local subprocesses, Docker containers, Kubernetes pods, and Prefect-managed flow or task runs. These clients differ in how they start and monitor compute. They share the Pipes contract for context injection, message collection, exit handling, and result access. The Prefect client also maps the external run's terminal state to Dagster success or failure and attaches a link to the external run to the reported results. python_modules/…/subprocess.py python_modules/…/pipes.py python_modules/…/pipes.py python_modules/…/pipes.py
References: python_modules/…/client.py• L27-67 python_modules/…/subprocess.py• L27-48 python_modules/…/pipes.py• L58-73 python_modules/…/pipes.py• L350-378 python_modules/…/pipes.py• L46-118
Manual session API
open_pipes_session() is the lower-level API for a launcher that does not fit a managed client. The caller chooses the context injector and message reader. It must pass the session's bootstrap data to the external system, monitor or poll that system, and yield results during and after execution. python_modules/…/utils.py
This API is useful when an external service returns a job ID, starts more than one external writer, or needs service-specific completion and log handling. The communication contract stays the same even when the launch and transport steps are custom. python_modules/…/context.py python_modules/…/utils.py
References: python_modules/…/utils.py• L861-912 python_modules/…/context.py• L338-381 python_modules/…/utils.py• L269-325
Protocol messages
Pipes messages are versioned JSON objects with a method name and a parameter payload. The external process sends these messages to the orchestration process. The orchestration side validates the method and maps it to Dagster logs, results, or engine events. python_modules/…/__init__.py python_modules/…/context.py
Result messages
The result messages connect external compute to Dagster's asset model. An external process can report a materialization with an asset key, metadata, and an optional data version. It can also report an asset check with a name, pass state, severity, and metadata. python_modules/…/__init__.py
The orchestration side turns these messages into MaterializeResult and AssetCheckResult values. A single-asset caller can use a convenience result method. A multi-asset caller should use the full result sequence so each reported result remains distinct. python_modules/…/context.py python_modules/…/client.py
References: python_modules/…/__init__.py• L1806-1887 python_modules/…/context.py• L182-224 python_modules/…/client.py• L82-127
Log and custom messages
The external context provides a logger that sends log messages through the same message path. It also supports a custom JSON payload for data that the orchestration process should receive but that is not itself an asset result. python_modules/…/__init__.py
Message readers can also forward external stdout and stderr. This keeps compute logs visible while reserving protocol messages for structured handling. The completed invocation exposes custom payloads through get_custom_messages(). python_modules/…/context.py python_modules/…/client.py
References: python_modules/…/__init__.py• L1889-1906 python_modules/…/context.py• L226-241 python_modules/…/client.py• L119-135
Transport roles
Pipes separates what is exchanged from where it is exchanged. A context injector and context loader move the context toward the external process. A message reader and message writer move structured output back to Dagster. This separation lets one protocol work across local files, process streams, and shared remote storage.
Local transports
The default local path uses temporary files. The orchestration process writes context to one file and tails another for messages. The external process receives the file paths through the bootstrap parameters. python_modules/…/utils.py python_modules/…/utils.py
Some launch environments instead place protocol messages in stdout or stderr. Container clients can read those streams and separate protocol lines from ordinary logs. The transport choice follows the access that both processes have to the same channel. python_modules/…/pipes.py python_modules/…/pipes.py
References: python_modules/…/utils.py• L48-107 python_modules/…/utils.py• L136-242 python_modules/…/pipes.py• L28-55 python_modules/…/pipes.py• L300-347
Remote transports
Remote compute uses the same roles with a shared location instead of a local file. Blob-store readers and writers exchange message chunks and can attach log readers when the external system writes logs on a separate path. Composite readers support one Dagster invocation that launches several independent external writers. python_modules/…/utils.py python_modules/…/utils.py python_modules/…/utils.py
The remote transport must give the orchestration process a reliable way to find each context and message stream. Custom injectors, loaders, readers, and writers are the extension points when the external platform has its own storage or launch metadata. Ecosystem and deployment
References: python_modules/…/utils.py• L390-459 python_modules/…/utils.py• L668-713 python_modules/…/utils.py• L269-325
Result handoff
Pipes does not make the external process's return value the asset result. The external process reports typed messages. The Dagster-side caller then returns or yields the resulting Dagster values so the run event stream records them.
Invocation results
After a managed client finishes, PipesClientCompletedInvocation provides the reported result sequence. It can also add launch metadata to every result, which is useful for identifiers returned by an external service. python_modules/…/client.py
The common single-asset pattern is to return run(...).get_materialize_result(). A caller that handles several assets or mixed result types uses get_results() instead. examples/…/dagster_code.py
References: python_modules/…/client.py• L58-99 examples/…/dagster_code.py• L6-17
External errors
If the external code exits inside the Pipes context, the close message can carry structured exception data. If the launch process itself exits with a failure status, the launch client reports external execution failure. These two paths preserve both the external error and the launch outcome. python_modules/…/__init__.py python_modules/…/subprocess.py
Managed clients for services that expose their own state also treat a non-success terminal state as external execution failure. The Prefect client polls the flow or task run until it reaches such a state before it completes the Pipes invocation. python_modules/…/pipes.py
References: python_modules/…/__init__.py• L1631-1652 python_modules/…/subprocess.py• L117-141 python_modules/…/pipes.py• L138-161
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the bootstrap parameter names and encoding rules aligned between
PipesSessionand the external params loaders. - Keep every protocol method and payload shape aligned between the external
PipesContextwriter and the orchestrationPipesMessageHandler. - Preserve the
openedandclosedlifecycle when changing buffering or remote message delivery. The session uses those messages to decide when it can safely drain and clean up. - When adding a launch client, preserve the
PipesClient.run()contract and return a completed invocation whose result stream is still yielded or returned by the Dagster asset or operation. - For service-backed clients, align the service's terminal states and cancellation behavior with the Dagster run outcome. A request to stop Dagster does not guarantee that the external service can stop its work.
- For multiple external writers, pair each writer with its own bootstrap message parameters and preserve the aggregate open and close counts.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The launcher does not pass the session bootstrap parameters | The external library cannot find the context or message channel. It may run as a no-op outside a Dagster Pipes process. | Pass PipesSession.get_bootstrap_env_vars() or the matching CLI arguments to the launched process. |
External code does not use open_dagster_pipes() as a context manager | The final closed message or buffered messages may not reach Dagster. | Keep the external business work inside the with open_dagster_pipes(): block. |
| A multi-asset process reports a materialization without an explicit asset key | Dagster cannot determine which in-scope asset the result belongs to. | Pass the asset key for each materialization, or use the single-asset form only when one asset is in scope. |
| A materialization is reported more than once for the same asset | The external context rejects the duplicate report. | Report one materialization per asset in a Pipes session. |
| A caller consumes a client invocation but does not return or yield its results | Dagster may not receive the materialization or check event stream. | Return get_materialize_result() for one asset or yield/return get_results() for a result sequence. |
| The external process exits with a non-zero status | The launch client marks the external execution as failed even if some messages were received. | Treat the external process exit status as part of the launch contract and inspect the external logs. |
| A Prefect flow or task reaches a terminal state other than completed | The Prefect Pipes client raises an external execution error instead of completing the Dagster invocation. | Inspect the Prefect state and message. Treat the service state as part of the Dagster launch contract. |
| Dagster terminates while a Prefect task run is active | Prefect cannot cancel the task run through this client. The task worker can continue the work after Dagster stops waiting. | Use a flow run when cancellation must reach Prefect, or account for the task's continued lifetime. |
Key files
| File | Why to read it |
|---|---|
| python_modules/…/__init__.py | Defines the external-side context, protocol message shapes, loaders, writers, and reporting API. |
| python_modules/…/pyproject.toml | Defines the external library's supported Python range and optional package support. |
| python_modules/…/uv.lock | Records the locked environment range and dependency resolution for the external library. |
| python_modules/…/context.py | Defines the Dagster-side session state, message handling, context payload, and result conversion. |
| python_modules/…/client.py | Defines the common client contract and the completed invocation result API. |
| python_modules/…/utils.py | Defines session setup plus the local, remote, log, and multi-writer transport roles. |
| python_modules/…/subprocess.py | Shows the smallest managed launch client for an external process. |
| python_modules/…/pipes.py | Shows how a container launch maps container logs and environment values into Pipes. |
| python_modules/…/pipes.py | Shows how a Kubernetes pod launch maps pod lifecycle and logs into Pipes. |
| python_modules/…/pipes.py | Shows how a Prefect flow or task launch carries Pipes context, polls external state, handles termination, and adds run metadata to results. |
| examples/…/dagster_code.py | Shows the Dagster-side single-asset launch and result handoff. |
| examples/…/external_code.py | Shows the external-side connection and materialization report. |
| docs/…/dagster-pipes-details-and-customization.md | Provides the broader Pipes terms and the extension model for custom platforms. |