Overview
TheNBDeployer class is a wrapper over Deployer for deploying flows defined in a Jupyter notebook cell. It automatically extracts the flow code from the notebook cell and creates a temporary Python file for deployment.
Usage
InstantiateNBDeployer on the last line of a notebook cell where a flow is defined. Unlike Deployer, this class is not meant to be used as a context manager.
Constructor
NBDeployer(flow, show_output=True, profile=None, env=None, base_dir=None, file_read_timeout=3600, **kwargs)
Create a new NBDeployer instance for deploying a flow defined in a notebook cell.
Parameters:
Flow class defined in the same notebook cell.
Show the stdout and stderr to the console by default.
Metaflow profile to use to deploy this flow. If not specified, the default profile is used (or the one already set using
METAFLOW_PROFILE).Additional environment variables to set. This overrides the environment set for this process.
The directory to run the subprocess in. If not specified, the current working directory is used.
The timeout in seconds until which we try to read the deployer attribute file.
Additional arguments that you would pass to
python myflow.py (i.e., options listed in python myflow.py --help).NBDeployerInitializationError - If NBDeployer is not used in an interactive Python environment (such as Jupyter).
Methods
TheNBDeployer class forwards all attribute access to the underlying Deployer instance. This means you can use all the orchestrator methods available on Deployer.
Orchestrator Methods
argo_workflows(**deployer_kwargs)
Create a deployer for Argo Workflows.
Returns: An orchestrator-specific deployer object that can be used to create, delete, and manage deployments.
Example:
step_functions(**deployer_kwargs)
Create a deployer for AWS Step Functions.
Returns: An orchestrator-specific deployer object that can be used to create, delete, and manage deployments.
Example:
cleanup()
Delete any temporary files created during deployment.
Example:
Workflow
A typical workflow withNBDeployer follows these steps:
- Define the flow in a notebook cell
- Create the deployer:
deployer = NBDeployer(MyFlow) - Select orchestrator:
argo = deployer.argo_workflows(name='my-flow') - Create deployment:
deployed_flow = argo.create() - Trigger runs:
triggered_run = deployed_flow.trigger(param1=value1) - Monitor execution:
triggered_run.wait_for_run()orprint(triggered_run.run) - Clean up (optional):
deployer.cleanup()
Differences from Deployer
- No context manager:
NBDeployeris not meant to be used as a context manager - Notebook-specific: Automatically extracts flow code from the notebook cell
- Attribute forwarding: All method calls are forwarded to the underlying
Deployerinstance - Environment handling: Automatically clears the
JPY_PARENT_PIDenvironment variable to prevent interference
Notes
NBDeployerrequires an interactive Python environment (such as Jupyter)- The flow must be defined in the same notebook cell as the
NBDeployerinstantiation - Temporary flow files are created in
base_dir(or the current working directory) - Remember to call
cleanup()when you’re done to remove temporary files - The deployed flow persists on the orchestrator even after calling
cleanup()- this only removes local temporary files
Related Classes
For more information on the classes returned byNBDeployer, see:
