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:
- Fetch the needed parameters to populate the
JobDetailsinstance from the environment variables or use the passed values to theload()method. - Look for the files corresponding to the passed DIDs in the filesystem according to the Ocean Protocol Structure and load them into the
JobDetailsinstance.
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file oceanprotocol_job_details-0.2.6.tar.gz.
File metadata
- Download URL: oceanprotocol_job_details-0.2.6.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edd79d0fcfdb18baff373f96f980c4fc6d5ee1e20a6efce3ea7dd8fd161db470
|
|
| MD5 |
2ba49a115d1346b2376fa15322a6a7db
|
|
| BLAKE2b-256 |
9fecb7403b572f6bfd0b8fcaba0218c7330f2faefd06d427b0e18711d85d9e6b
|
File details
Details for the file oceanprotocol_job_details-0.2.6-py3-none-any.whl.
File metadata
- Download URL: oceanprotocol_job_details-0.2.6-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b49a28422b6548ea15c7fd32cc8eefe44de1e4dd39e4bbcf0d426f7e5decfbd3
|
|
| MD5 |
07d1aee11a1b4871183f2b0670bf2bd6
|
|
| BLAKE2b-256 |
e320b31b816cf519d36abae219e9567711fb41341573a2ad4a95fdf37e010a62
|