Back to examples
Artifacts
Text Artifact
Produce and persist a plain-text file as a pipeline artifact.
When to use
Use this when a task needs to output a human-readable file (report, log, config) that should be stored alongside the run result.
artifacts/text-artifact.py
"""
01_text_artifact.py: Producing a plain-text LocalArtifact.
Demonstrates:
- Returning LocalArtifact(type="text", ...) from a task
- Artifact filename is stored alongside the run result
"""
from dagy import LocalArtifact, flow, task
@task
def generate_report(title: str, lines: int) -> str:
rows = "\n".join(f" Row {i+1}: value={i * 10}" for i in range(lines))
return f"=== {title} ===\n{rows}\n=== END ==="
@task
def save_report(content: str, filename: str) -> LocalArtifact:
return LocalArtifact(type="text", value=content, filename=filename)
@flow(name="text_artifact_flow")
def text_artifact_flow(title: str = "Daily Report", lines: int = 5) -> None:
report = generate_report(title, lines)
save_report(report, "daily_report.txt")
if __name__ == "__main__":
result = text_artifact_flow.run_local(title="March Summary", lines=3)
print(f"Run ID : {result.run_id}")
print(f"Status : {result.status}")How it works
- `generate_report` builds a multi-line text report from a title and line count.
- `save_report` wraps the text in a `LocalArtifact(type="text", ...)` and returns it.
- DAGY detects the `LocalArtifact` return type and persists the file automatically.
- The artifact is associated with the run and can be downloaded later.
Inputs
- `title` (str, default `"Daily Report"`): report heading.
- `lines` (int, default `5`): number of data rows.
Outputs
- A `.txt` file stored as a run artifact.
Dependencies
`dagy`, `LocalArtifact`