Skip to main content

A Framework for creating a boilerplate template for ai projects that are ready for MLOps

Project description

pyPhases

Foundation library for config-driven pipeline frameworks. Provides Phase, Config, Project, and Exporter abstractions.

Documentation

Install

pip install pyPhases phases

Quick start

from pyPhases import Phase

class MyPhase(Phase):
    def main(self):
        value = self.getConfig("myKey")
        self.registerData("result", value)

arch

Install

Python >= 3.6 is required.

pip install phases pyPhases

Hello World Example

Open in Gitpod

The project is using two phases, one to generate the sentence to be said and the other one to actually say it.

First we need a data directory where where the data will be stored (default data): mkdir data

poject.yaml

name: HelloWorld

exporter:
   # exporter that can handle primitive types
 - PickleExporter

phases:
   - name: GenerateIt
     exports:
       - sentence
   - name: SayIt

data:
 - name: sentence
   dependsOn:
     - who

config:
 who: world

HelloWorld/phases/GenerateIt.py

from pyPhases import Phase


class GenerateIt(Phase):
    """This phase generates the sentence to be said."""

    def main(self):
        self.log("Generating the sentence")
        greetWho = self.getConfig("who")
        self.registerData("sentence", "Hello %s!" % greetWho)

HelloWorld/phases/SayIt.py

from pyPhases import Phase


class SayIt(Phase):
   """This phase says the sentence."""

   def main(self):
       sentence = self.getData("sentence", str)
       self.logSuccess(sentence)

Run the Example: python -m phases run SayIt

First Output will generate the sentence in phase GenerateIt:

gitpod /workspace/pyphases-hello-world (main) $ phases run SayIt
[phases] Phases v1.0.2 with pyPhases v1.1.5 (Log level: LogLevel.INFO)
[SayIt] RUN phase SayIt: SayIt
[Project] Data sentenceworld--current was not found, try to find phase to generate it
[GenerateIt] RUN phase GenerateIt: GenerateIt
[GenerateIt] Generating the sentence
[SayIt] Hello world!

The data is now stored in the file: data/sentence--current

If your run it again (python -m phases run SayIt) the data is loaded using the Pickleexporter:

gitpod /workspace/pyphases-hello-world (main) $ phases run SayIt
[phases] Phases v1.0.2 with pyPhases v1.1.5 (Log level: LogLevel.INFO)
[SayIt] RUN phase SayIt: SayIt
[SayIt] Hello world!

If you change the config value who in the project to whole world. The data is generated again:

gitpod /workspace/pyphases-hello-world (main) $ phases run --set who="whole world" SayIt
[phases] Phases v1.0.2 with pyPhases v1.1.5 (Log level: LogLevel.INFO)
[SayIt] RUN phase SayIt: SayIt
[Project] Data sentencewholeworld--current was not found, try to find phase to generate it
[GenerateIt] RUN phase GenerateIt: GenerateIt
[GenerateIt] Generating the sentence
[SayIt] Hello whole world!

if you want to explicit generate the data you can just run the first phase: python -m phases run GenerateIt

Example projects

Data with parameter

For getting Data with parameter all data handler need to support the additional parameters.

project.getData('metadata', pd.DataFrame, myid=1)

requires the Exporter:

  • to have the attribute dataHandler = True
  • the method getDataHandler(self, data) that returns a datahandler for a specific data instance.
  • the get method get(self, **kwargs) that returns the data or tailored data depending on the kwargs, e.g. get(self, myid=1)

the phase that generates the data needs a compatible generateData method such as generateData(self, dataName, myId=None):

Development

build

python setup.py sdist bdist_wheel

publish

twine upload dist/*

documentation

sphinx-apidoc -o docs/source pyPhases sphinx-build -b html docs/source docs/build

test

python -m unittest discover -v

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyphases-0.7.1.tar.gz (36.5 kB view details)

Uploaded Source

File details

Details for the file pyphases-0.7.1.tar.gz.

File metadata

  • Download URL: pyphases-0.7.1.tar.gz
  • Upload date:
  • Size: 36.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for pyphases-0.7.1.tar.gz
Algorithm Hash digest
SHA256 b2c45542992c2753dfa2528326dcd05bbc9956949d88bdc815c65f032ef6195e
MD5 b550081bfd410404de4c5b05b62a46ab
BLAKE2b-256 4a377ad1d37287e50b9e2df0b907305997d0e5da70aa9ee44c7d4e75ba74f907

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page