oceanprotocol-job-details 0.3.1__py3-none-any.whl → 0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
+ from .helpers import create_container, load_job_details
1
2
  from .ocean import JobDetails
2
3
 
3
-
4
- __all__ = [JobDetails] # type: ignore
4
+ __all__ = [JobDetails, load_job_details, create_container] # type: ignore
@@ -0,0 +1,29 @@
1
+ from typing import Any, Dict, Type, TypeVar
2
+
3
+ from pydantic import BaseModel, JsonValue
4
+
5
+ from oceanprotocol_job_details.di import Container
6
+ from oceanprotocol_job_details.ocean import JobDetails
7
+ from oceanprotocol_job_details.settings import JobSettings
8
+
9
+ InputParametersT = TypeVar("InputParametersT", bound=BaseModel)
10
+
11
+
12
+ def create_container(config: Dict[str, Any]) -> Container[InputParametersT]: # type: ignore[explicit-any]
13
+ """Return a fully configured Container from a config dict."""
14
+ container = Container[InputParametersT]()
15
+ settings = JobSettings(**config)
16
+ container.config.from_pydantic(settings)
17
+ return container
18
+
19
+
20
+ def load_job_details(
21
+ config: Dict[str, JsonValue],
22
+ input_type: Type[InputParametersT],
23
+ ) -> JobDetails[InputParametersT]:
24
+ """
25
+ Load JobDetails for a given input_type using the config.
26
+ Returns a fully initialized JobDetails instance.
27
+ """
28
+ container: Container[InputParametersT] = create_container(config)
29
+ return container.job_details_loader(input_type=input_type).load()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oceanprotocol-job-details
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: A Python package to get details from OceanProtocol jobs
5
5
  Project-URL: Homepage, https://github.com/AgrospAI/oceanprotocol-job-details
6
6
  Project-URL: Issues, https://github.com/AgrospAI/oceanprotocol-job-details/issues
@@ -30,24 +30,29 @@ A Python package to get details from OceanProtocol jobs
30
30
 
31
31
  ## Installation
32
32
 
33
- ```
33
+ ```bash
34
34
  pip install oceanprotocol-job-details
35
35
  ```
36
36
 
37
- ## Usage
37
+ ```bash
38
+ uv add oceanprotocol-job-details
39
+ ```
40
+
41
+ ## Usage
38
42
 
39
- As a simple library, we only need to import `JobDetails` and load it, it will:
43
+ As a simple library, we only need to import `load_job_details` and run it. It will:
40
44
 
41
- 1. Fetch the needed parameters to populate the `JobDetails` instance from the environment variables or use the passed values to the `load()` method.
45
+ 1. Fetch the needed parameters to populate the `JobDetails` instance from the environment variables or use the passed values to the function.
42
46
  1. Look for the files corresponding to the passed DIDs in the filesystem according to the [Ocean Protocol Structure](#oceanprotocol-structure) and load them into the `JobDetails` instance.
43
47
 
44
-
45
48
  ### Minimal Example
46
49
 
47
50
  ```python
48
- from oceanprotocol_job_details import JobDetails
51
+ from oceanprotocol_job_details import load_job_details
49
52
 
50
- job_details = JobDetails.load()
53
+ class InputParameters(BaseModel): ...
54
+
55
+ job_details = load_job_details({}, InputParameters)
51
56
  ```
52
57
 
53
58
  ### Custom Input Parameters
@@ -55,58 +60,40 @@ job_details = JobDetails.load()
55
60
  If our algorithm has custom input parameters and we want to load them into our algorithm, we can do it as follows:
56
61
 
57
62
  ```python
58
- from dataclasses import dataclass
59
- from oceanprotocol_job_details import JobDetails
60
-
61
-
62
- @dataclass
63
- class InputParameters:
64
- foobar: str
65
-
66
-
67
- job_details = JobDetails[InputParameters].load(InputParameters)
68
-
69
- # Usage
70
- job_details.input_parameters.foobar
71
- ```
72
-
73
- ```python
74
- from dataclasses import dataclass
75
- from oceanprotocol_job_details import JobDetails
63
+ from pydantic import BaseModel
64
+ from oceanprotocol_job_details import load_job_details
76
65
 
77
66
 
78
- @dataclass
79
- class Foo:
67
+ class Foo(BaseModel):
80
68
  bar: str
81
69
 
82
70
 
83
- @dataclass
84
- class InputParameters:
71
+ class InputParameters(BaseModel):
85
72
  # Allows for nested types
86
73
  foo: Foo
87
74
 
88
75
 
89
- job_details = JobDetails[InputParameters].load(InputParameters)
76
+ job_details = load_job_details({}, InputParameters)
90
77
 
91
78
  # Usage
79
+ job_details.input_parameters.foo
92
80
  job_details.input_parameters.foo.bar
93
81
  ```
94
82
 
95
- The values to fill the custom `InputParameters` will be parsed from the `algoCustomData.json` located next to the input data directories.
83
+ The values to fill the custom `InputParameters` will be parsed from the `algoCustomData.json` located next to the input data directories.
96
84
 
97
85
  ### Iterating Input Files the clean way
98
86
 
99
87
  ```python
100
- from oceanprotocol_job_details import JobDetails
88
+ from oceanprotocol_job_details import load_job_details
101
89
 
102
90
 
103
- job_details = JobDetails.load()
91
+ job_details = load_job_details
104
92
 
105
- for idx, file_path in job_details.next_file():
93
+ for idx, file_path in job_details.inputs():
106
94
  ...
107
95
 
108
- # Or if you just want one file path
109
- _, file_path = job_details.next_file()
96
+ _, file_path = next(job_details.inputs())
110
97
  ```
111
98
 
112
99
  ## OceanProtocol Structure
@@ -124,4 +111,4 @@ data # Root /data directory
124
111
  └── outputs # Algorithm output files dir
125
112
  ```
126
113
 
127
- > **_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`.
114
+ > **_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`.
@@ -1,6 +1,7 @@
1
- oceanprotocol_job_details/__init__.py,sha256=iVJs6gQHV84d25iTq2Ot-R2BDWMor5jum04Wh_PuYzg,71
1
+ oceanprotocol_job_details/__init__.py,sha256=nJMrZsEC5F1n9WF-v5QV095Yyc8UkhFw0AzD9o7X0IE,162
2
2
  oceanprotocol_job_details/di.py,sha256=lsogbmjvmPfkd0mjLvn9vYLIZebwJm5RNraWt7WE5LA,1316
3
3
  oceanprotocol_job_details/domain.py,sha256=2_USbeA_7VIEYS8DVb2MW6dCZasjiqIxQaGUnNUKspY,3851
4
+ oceanprotocol_job_details/helpers.py,sha256=ubH_KjAROqYvn0mkbA0-89vpdKIhVNGZ0h9pQLfPNow,1045
4
5
  oceanprotocol_job_details/ocean.py,sha256=q8rgT5ycA2ifey3XNhUW0bcJwfMp7hpKU-6EVDeKV1o,1620
5
6
  oceanprotocol_job_details/settings.py,sha256=Xliw3SXSGboCp2OqF-yzXVLDuEoq9kAPhQQSMuHSoDg,1014
6
7
  oceanprotocol_job_details/loaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -9,7 +10,7 @@ oceanprotocol_job_details/loaders/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JC
9
10
  oceanprotocol_job_details/loaders/impl/ddo.py,sha256=XthrQFhmP85XSVzVjBlLePtTowGR3BAsmVp3jngiQ08,668
10
11
  oceanprotocol_job_details/loaders/impl/files.py,sha256=3Zg7JnxT67iFKsd95VVKYMEYZgjPcGU4Kqpo2B9aZQI,1327
11
12
  oceanprotocol_job_details/loaders/impl/job_details.py,sha256=7mEdeTo-cmsWuqWPdN7btjLjo6p5Oa1_acjSLWL5tb8,697
12
- oceanprotocol_job_details-0.3.1.dist-info/METADATA,sha256=6TRbrQ3P91_U1sjami7o5r0SwS-BNZNMiJym0yaI0IA,4573
13
- oceanprotocol_job_details-0.3.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
- oceanprotocol_job_details-0.3.1.dist-info/licenses/LICENSE,sha256=ni3ix7P_GxK1W3VGC4fJ3o6QoCngCEpSuTJwO4nkpbw,1055
15
- oceanprotocol_job_details-0.3.1.dist-info/RECORD,,
13
+ oceanprotocol_job_details-0.3.2.dist-info/METADATA,sha256=VDGsLGPWchYb0Or1sEmqQw3bJxh5y8z6NdAkEF8qXgE,4416
14
+ oceanprotocol_job_details-0.3.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
15
+ oceanprotocol_job_details-0.3.2.dist-info/licenses/LICENSE,sha256=ni3ix7P_GxK1W3VGC4fJ3o6QoCngCEpSuTJwO4nkpbw,1055
16
+ oceanprotocol_job_details-0.3.2.dist-info/RECORD,,