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. API Reference

prism.target.PrismTarget

Subclasses of the prism.target.Target class

class PrismTarget:

    def __init__(self, obj, loc):
        self.obj = obj
        self.loc = loc

    def save(self):
        raise prism.exceptions.RuntimeException(message="`save` method not implemented")

    @classmethod
    def open(cls, loc):
        raise prism.exceptions.RuntimeException(message="`open` method not implemented")


class PandasCsv(PrismTarget):

    def save(self, **kwargs):
        self.obj.to_csv(self.loc, **kwargs)

    @classmethod
    def open(cls, loc):
        import pandas as pd
        obj = pd.read_csv(loc)
        return cls(obj, loc)


class NumpyTxt(PrismTarget):

    def save(self, **kwargs):
        import numpy as np
        np.savetxt(self.loc, self.obj, **kwargs)

    @classmethod
    def open(cls, loc):
        import numpy as np
        obj = np.loadtxt(loc)
        return cls(obj, loc)


class Txt(PrismTarget):

    def save(self, **kwargs):
        with open(self.loc, "w") as f:
            f.write(self.obj, **kwargs)
        f.close()

    @classmethod
    def open(cls, loc):
        with open(loc, 'r') as f:
            obj = f.read()
        return cls(obj, loc)


class MatplotlibPNG(PrismTarget):

    def save(self, **kwargs):
        self.obj.savefig(self.loc, **kwargs)

    @classmethod
    def open(cls, loc):
        from PIL import Image
        obj = Image.open(loc)
        return cls(obj, loc)


class JSON(PrismTarget):

    def save(self, **kwargs):
        import json
        json_object = json.dumps(self.obj, **kwargs)
        with open(self.loc, "w") as f:
            f.write(json_object)

    @classmethod
    def open(cls, loc):
        import json
        with open(loc, 'r') as f:
            obj = json.loads(f.read())
        return cls(obj, loc)
Previous@target_iterator(...)NextAnalytics on top of dbt

Last updated 1 year ago