Skip to main content

A Python package to get details from OceanProtocol jobs

Project description

OceanProtocol Job Details

PyPI Coverage

A Python package to get details from OceanProtocol jobs

Installation

pip install oceanprotocol-job-details
#or
uv add oceanprotocol-job-details

Usage

As a simple library, we only need to import load_job_details and run it. It will:

  1. Read from disk the needed parameters to populate the JobDetails from the given base_dir. Looking for the files corresponding to the passed DIDs in the filesystem according to the Ocean Protocol Structure.
  2. If given a InputParameters type that inherits from pydantic.BaseModel, it will create an instance from the environment variables.

Minimal Example

from oceanprotocol_job_details import load_job_details

job_details = load_job_details({"base_dir": "...", "transformation_did": "..."})

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 pydantic import BaseModel
from oceanprotocol_job_details import load_job_details


class Foo(BaseModel):
    bar: str


class InputParameters(BaseModel):
    # Allows for nested types
    foo: Foo


job_details = load_job_details({"base_dir": "...", "transformation_did": "..."}, InputParameters)

# Usage
parameters = await job_details.input_parameters()
parameters.foo
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 load_job_details


job_details = load_job_details(...)

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

_, file_path = next(job_details.inputs())

OceanProtocol Structure

data        # Root /data directory
├── ddos    # Contains the loaded dataset's DDO (metadata)   ├── 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.4.1.tar.gz (8.1 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.4.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for oceanprotocol_job_details-0.4.1.tar.gz
Algorithm Hash digest
SHA256 3043d3c65e1ad792f14ab51d5258289ab9248456df9a2d76e978e5f8b7d365cc
MD5 5bc26338cd11c87ed8629bbfc4bab8af
BLAKE2b-256 75e6586944f4d6970ce7bd573b755b9da96b3d6de945e9315cdcf4b7e0b58660

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oceanprotocol_job_details-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6e49be1deeeb7f5a1f6a5e9013d5ba370cd427e9478aca3a2e195a7c3dc9f20
MD5 0bad3ea14419c8c2aa50a3c635bb64df
BLAKE2b-256 9ab7b5230e1f526f2683911f63b55be27fa38a08a59e7ab08d938ee7290e2c13

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