Skip to main content

A Python PyPI package template

Project description

ocean-runner

Ocean Runner is a package that brings a fluent API for APP creation and running in the scope of OceanProtocol.

Usage

Minimal Example

import random
from ocean_runner import Algorithm, Config


Algorithm().run(lambda _: random.randint()).save_results()    

To use minimally the API, you can just provide a callback to the run method, defaulting for the rest of behaviours. This code snippet will:

  • Read the OceanProtocol JobDetails from the environment variables and use default file paths.
  • Generate a random integer.
  • Store the result in a "result.txt" file within the default outputs path.

Tuning

Application Config

The application configuration can be tweaked by passing a Config instance to its' constructor.

Algorithm(
    Config(
        custom_input: ... # dataclass
        # Custom algorithm parameters dataclass.
        
        error_callback: ... # Callable[[Exception], None]
        # Callback to run on exceptions.
        
        logger: ... # type: logging.Logger
        # Custom logger to use.
        
        environment: ... 
        # type: ocean_runner.Environment. Mock of environment variables.
    )
)
import logging


@dataclass
class CustomInput:
    foobar: string 


logger = logging.getLogger(__name__)


Algorithm(
    Config(
        custom_input: CustomInput,
        """
        Load the Algorithm's Custom Input into a CustomInput dataclass instance.
        """

        error_callback: lambda ex: logger.exception(ex),
        """
        Run this callback when an exception is caught
        NOTE: it's not recommended to catch exceptions this way. Should re-raise and halt the execution.
        """

        logger: logger,
        """
        Custom logger to use in the Algorithm.
        """

        environment: Environment(
            base_dir: "./_data",
            """
            Custom data path to use test data.
            """

            dids: '["17feb697190d9f5912e064307006c06019c766d35e4e3f239ebb69fb71096e42"]',
            """
            Dataset DID.
            """

            transformation_did: "1234",
            """
            Random transformation DID to use while testing.
            """

            secret: "1234",
            """
            Random secret to use while testing.
            """
        )
        """
        Should not be needed in production algorithms, used to mock environment variables, defaults to using env.
        """
    )
)

Default behaviours

Default implementations

As seen in the minimal example, all methods implemented in Algorithm have a default implementation which will be commented here.

(
    Algorithm()
    
        """
        Default constructor, will use default values of Config.
        """
    
    .validate()
    
        """
        Will validate the algorithm's job detail instance, checking for the existence of:
        - `job_details.ddos` 
        - `job_details.files`
        """

    .run()

        """ 
        Has NO default implementation, must pass a callback that returns a result of any type.
        """

    .save_results()

        """
        Stores the result of running the algorithm in "outputs/results.txt"
        """

)

Job Details

To load the OceanProtocol JobDetails instance, the program will read some environment variables, they can be mocked passing an instance of Environment through the configuration of the algorithm.

Environment variables:

  • DIDS: Input dataset(s) DID's.
  • TRANSFORMATION_DID: Algorithm DID.
  • SECRET: Algorithm secret.
  • BASE_DIR (optional, default='/data'): Base path to the OceanProtocol data directories.

Project details


Download files

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

Source Distribution

ocean_runner-0.1.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ocean_runner-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file ocean_runner-0.1.0.tar.gz.

File metadata

  • Download URL: ocean_runner-0.1.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for ocean_runner-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9131542df8999e1a1fb0ec896d5a276e44a1c85f392615200d4f10c4a1900af2
MD5 c2cb58e40b7e05c55bee351c4363d52e
BLAKE2b-256 e21285062be54a5dcb64481c8a9c31fb20f713cb5fded5920e4f263aa0608848

See more details on using hashes here.

File details

Details for the file ocean_runner-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ocean_runner-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for ocean_runner-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3cd9d6d5c5493ac9208e73a785f6a3e5fa4951bea34f58dce229441235ee521
MD5 dc4dfbac617be4178affdb31bb8dad4e
BLAKE2b-256 5fd988d72f08f185470842758aa7624c2bb44083ba9fa00713eb0efbe043a4b2

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