Prism
v0.1.9rc2
v0.1.9rc2
  • 👋Welcome to Prism!
  • Getting Started
    • Installation
    • Creating your first project
    • Why Prism?
  • Fundamentals
    • Tasks
      • tasks
      • hooks
        • hooks.sql
        • hooks.spark
        • hooks.dbt_ref
    • Targets
      • Multiple targets
    • Config files
      • prism_project.py
        • RUN_ID / SLUG
        • SYS_PATH_CONF
        • THREADS
        • PROFILE_YML_PATH / PROFILE
        • PRISM_LOGGER
        • TRIGGERS_YML_PATH / TRIGGERS
      • Profile YML
      • Triggers YML
    • Jinja
      • __file__ and Path
      • prism_project
      • wkdir
      • parent_dir
      • concat
      • env
  • Adapters
    • Overview
    • sql
      • BigQuery
      • Postgres
      • Redshift
      • Snowflake
      • Trino
    • PySpark
    • dbt
  • Agents
    • Overview
    • Docker
    • EC2
  • CLI
    • Command Line Interface
    • init
    • compile
    • connect
    • create
      • agent
      • task
      • trigger
    • graph
    • run
    • spark-submit
    • agent
      • apply
      • run
      • build
      • delete
  • Advanced features
    • Concurrency
    • Logging
    • Triggers
    • Retries
    • Python Client
  • API Reference
    • prism.task.PrismTask
    • @task(...)
    • @target(...)
    • @target_iterator(...)
    • tasks.ref(...)
    • hooks.sql(...)
    • hooks.dbt_ref(...)
  • Use Cases
    • Analytics on top of dbt
    • Machine Learning
  • Wiki
    • DAGs
Powered by GitBook
On this page
  1. API Reference

@target_iterator(...)

Decorator used to write the outputs of a task function.

prism.decorators.target_iterator(*, type: prism.target.PrismTarget, loc: Union[str, pathlib.Path])

  • Parameters

    • *: indicates that the target_iterator decorator only accepts keyword arguments.

    • type: a valid Prism target. This controls the output type, e.g., a .txt file, a .csv, a .json, etc. Prism targets are classes that inherit the prism.target.PrismTarget class and implement the save method. See here.

    • loc: a string or path-like object represent the parent directory in which the outputs should be saved.

  • Technical notes:

    • The target_iterator function requires that the task function return a dictionary mapping the name of the desired output file to the associated object.

Example:

import prism.task
import prism.target
import prism.decorators

class ExampleTask(prism.task.PrismTask):
    
    @prism.decorators.target_iterator(
        type=prism.target.Txt, 
        loc="/Users/,
        **kwargs
    )
    def run(self, tasks, hooks):
        test_str = "Hello, world!"
        test_str_2 = "This is a second string"
        return {
            "hello_world.txt": test_str,
            "other_string.txt": test_str_2,
        }
from prism.decorators import task, target_iterator
import prism.target

@task(
    targets=[
        target_iterator(type=prism.target.Txt, loc="/Users/")
    ]
)
def example_function(tasks, hooks):
    test_str = "Hello, world!"
    test_str_2 = "This is a second string"
    return {
        "hello_world.txt": test_str,
        "other_string.txt": test_str_2,
    }

Previous@target(...)Nexttasks.ref(...)

Last updated 1 year ago