Skip to main content

A Python package to get details from OceanProtocol jobs

Project description

A Python package to get details from OceanProtocol jobs


Installation

pip install oceanprotocol-job-details

Usage

As a simple library, we only need to import JobDetails and load it, it will:

  1. Fetch the needed parameters to populate the JobDetails instance from the environment variables or use the passed values to the load() method.
  2. Look for the files corresponding to the passed DIDs in the filesystem according to the Ocean Protocol Structure and load them into the JobDetails instance.

Minimal Example

from oceanprotocol_job_details import JobDetails

job_details = JobDetails.load()

Custom Input Parameters

If our algorithm has custom input parameters and we want to load them into our algorithm, we can do it as follows:

from dataclasses import dataclass
from oceanprotocol_job_details import JobDetails


@dataclass
class InputParameters:
    foobar: str


job_details = JobDetails[InputParameters].load(InputParameters)

# Usage
job_details.input_parameters.foobar
from dataclasses import dataclass
from oceanprotocol_job_details import JobDetails


@dataclass
class Foo:
    bar: str


@dataclass
class InputParameters:
    # Allows for nested types
    foo: Foo


job_details = JobDetails[InputParameters].load(InputParameters)

# Usage
job_details.input_parameters.foo.bar

The values to fill the custom InputParameters will be parsed from the algoCustomData.json located next to the input data directories.

Iterating Input Files the clean way

from oceanprotocol_job_details import JobDetails


job_details = JobDetails.load()

for idx, file_path in job_details.next_file():
    ...

# Or if you just want one file path
_, file_path = job_details.next_file()

OceanProtocol Structure

data        # Root /data directory
├── ddos    # Contains the loaded dataset's DDO   ├── 17feb...e42 # DDO file   └── ... # One DDO per loaded dataset
├── inputs  # Datasets dir   ├── 17feb...e42 # Dir holding the data of its name DID, contains files named 0..X      └── 0 # Data file   └── algoCustomData.json # Custom algorithm input data
├── logs    # Algorithm output logs dir
└── outputs # Algorithm output files dir

Note: Even though it's possible that the algorithm is passed multiple datasets, right now the implementation only allows to use one dataset per algorithm execution, so normally the executing job will only have one ddo, one dir inside inputs, and one data file named 0.

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

oceanprotocol_job_details-0.2.7.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

oceanprotocol_job_details-0.2.7-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file oceanprotocol_job_details-0.2.7.tar.gz.

File metadata

File hashes

Hashes for oceanprotocol_job_details-0.2.7.tar.gz
Algorithm Hash digest
SHA256 1e490532f89c30045fc29ff42e8d5a8d09ba92a8d319a90359c6826aab2f8240
MD5 502bbdfb78b8300f0dcc430449288b00
BLAKE2b-256 11fa0035d19f6c5547cd8a0b281b12a1524725d40d7e2787e54c9e496c937401

See more details on using hashes here.

File details

Details for the file oceanprotocol_job_details-0.2.7-py3-none-any.whl.

File metadata

File hashes

Hashes for oceanprotocol_job_details-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1b97b82a754da7e90e251c4a3118a4d5059fd017b0c1e49fd4dc1be64a4a2f43
MD5 e7e5dd588f7682766ed8832d5996dc98
BLAKE2b-256 63668704a600b7f3153b913bafd8cc67697f320925dfe7be2cca3d61b0d17875

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