o_utils.read_file_contents_as_string(artifact_uri)using a temporary local file/folder to serialize and copy in-memory objects to/from the artifact store (heavily used in Materializers to transfer information between the Artifact Store and external libraries that don't support writing/reading directly to/from the artifact store backend):

import os

import tempfile

import external_lib

root_path = Repository().active_stack.artifact_store.path

artifact_path = os.path.join(root_path, "artifacts", "examples")

artifact_uri = os.path.join(artifact_path, "test.json")

fileio.makedirs(artifact_path)

with tempfile.NamedTemporaryFile(

mode="w", suffix=".json", delete=True

) as f:

external_lib.external_object.save_to_file(f.name)

# Copy it into artifact store

fileio.copy(f.name, artifact_uri)

import os

import tempfile

import external_lib

root_path = Repository().active_stack.artifact_store.path

artifact_path = os.path.join(root_path, "artifacts", "examples")

artifact_uri = os.path.join(artifact_path, "test.json")

with tempfile.NamedTemporaryFile(

mode="w", suffix=".json", delete=True

) as f:

# Copy the serialized object from the artifact store

fileio.copy(artifact_uri, f.name)

external_lib.external_object.load_from_file(f.name)

PreviousDevelop a custom orchestrator

NextLocal Artifact Store

Last updated 19 days ago