Prism
v0.3.0
v0.3.0
  • 👋Welcome to Prism!
  • Getting Started
    • Installation
    • Creating your first project
    • Why Prism?
  • Fundamentals
    • PrismProject API
      • PrismProject().run
      • PrismProject().graph
    • Tasks
    • Targets
      • Multiple targets
    • CurrentRun API
      • CurrentRun.ref()
      • CurrentRun.conn()
      • CurrentRun.ctx()
  • Connectors
    • Overview
    • BigQueryConnector
    • PostgresConnector
    • RedshiftConnector
    • SnowflakeConnector
    • TrinoConnector
    • PrestoConnector
  • CLI
    • Command Line Interface
    • graph
    • init
    • run
  • Advanced features
    • Concurrency
    • Logging
    • Callbacks
    • Retries
    • Skipping tasks
  • API Reference
    • prism.task.PrismTask
    • @task(...)
    • @target(...)
    • @target_iterator(...)
    • prism.target.PrismTarget
  • Use Cases
    • Analytics on top of dbt
    • Machine Learning
  • Wiki
    • DAGs
Powered by GitBook
On this page
  1. Fundamentals
  2. CurrentRun API

CurrentRun.ref()

CurrentRun.ref has two important jobs.

First, it's used to reference the output of tasks within your project. Remember, tasks have to return a non-null output (either themselves, if the task is a decorated function or via their run method if the task is a class). At runtime, Prism stores references to these outputted objects and makes them accessible via CurrentRun.ref(...).

Second, it's used to build a dependency graph between tasks. Put another way, Prism parses the CurrentRef.ref(...) calls and figures out the order in which tasks need to be run — if taskB calls CurrentRef.ref("taskA") in its body, then Prism knows to run taskA before taskB.

Here's the full method definition:

CurrentRun.ref(task_id: str) -> Any:
    """
    Get the output of task with ID `task_id`

    args:
        task_id: ID of task from which to retrieve output
    returns:
        the output of the inputted `task_id`
    raises:
        prism.exception.RefDoesNotExistException if the task ID is not found
    """

Example

# tasks/hello_world.py

import prism.task
import prism.target

class HelloWorld(prism.task.PrismTask):
    
    def run(self):
        test_str = "Hello, world!"
        return test_str
# tasks/second_task.py

import prism.task
import prism.target
from prism.runtime import CurrentRun

class SecondTask(prism.task.PrismTask):
    
    def run(self):
        hello_world_str = CurrentRun.ref("hello_world.HelloWorld")  # default task ID set by Prism
        additional_details = "\n" + "This is a Prism project"!
        return hello_world_str + additional_details
# tasks/hello_world.py

from prism.decorators import task

@task()
def hello_world():
    test_str = "Hello, world!"
    return test_str
# tasks/second_task.py

import prism.decorators import task

@task()
def second_task():
    hello_world_str = tasks.ref("hello_world.hello_world")  # default task ID set by Prism
    additional_details = "\n" + "This is a Prism project"!
    return hello_world_str + additional_details
PreviousCurrentRun APINextCurrentRun.conn()

Last updated 1 year ago

Our CurrentRun.ref() is located in the second task. We did not specify any custom in our HelloWorld task, so we need to reference the default task ID that Prism sets — <module_name>.<class name>.

task ID