CurrentRun.ctx() is used access context variables. These can be variables passed into the PrismProject's , or it can be variables passed into the at runtime.
Here is the full method definition:
CurrentRun.ctx(self, key: str, default_value: Optional[Any] = None) -> Any:
"""
Get the value associated with context variable `key`. Context variables can be
set in two places: when instantiated the PrismProject (with the `ctx` keyword
argument) and when creating the run job (with the `runtime_ctx` keyword argument
in the PrismProject's `create_run_job` method).
args:
key: variable to retrieve
default_value: default value to return if `key` is not found.
Default is `None`
returns:
value associated with context variable `key`
"""
Example
Here's an example project entrypoint:
# example_project/main.py
import os
from pathlib import Path
from prism.client import PrismProject
from prism.connectors import SnowflakeConnector
snowflake_conn = SnowflakeConnector(
id="snowflake-connector",
account=os.getenv("account"),
user=os.getenv("user"),
password=os.getenv("password"),
database=os.getenv("database"),
schema=os.getenv("schema"),
warehouse=os.getenv("warehouse"),
role=os.getenv("role"),
)
project = PrismProject(
tasks_dir=Path.cwd() / "tasks",
connectors=[snowflake_conn]
ctx={
"OUTPUT": Path.cwd() / "output"
}
)
if __name__ == "__main__":
project.run()
Tasks within this project can call the OUTPUT context variable as follows: