Skip to content

Commit

Permalink
Merge pull request #15 from ucbepic/shreyashankar/blockingerr
Browse files Browse the repository at this point in the history
Add a save config method to the Python API
  • Loading branch information
shreyashankar authored Sep 26, 2024
2 parents be8a8bb + 96a1034 commit 6595257
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docetl/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@
import os
from typing import List, Optional, Dict, Any, Union

import yaml

from docetl.builder import Optimizer
from docetl.runner import DSLRunner

from rich import print


@dataclass
class Dataset:
Expand Down Expand Up @@ -274,6 +278,22 @@ def run(self, max_threads: Optional[int] = None) -> float:
result = runner.run()
return result

def to_yaml(self, path: str) -> None:
"""
Convert the Pipeline object to a YAML string and save it to a file.
Args:
path (str): Path to save the YAML file.
Returns:
None
"""
config = self._to_dict()
with open(path, "w") as f:
yaml.safe_dump(config, f)

print(f"[green]Pipeline saved to {path}[/green]")

def _to_dict(self) -> Dict[str, Any]:
"""
Convert the Pipeline object to a dictionary representation.
Expand Down

0 comments on commit 6595257

Please sign in to comment.