codewords-client 0.1.0__tar.gz
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.
- codewords_client-0.1.0/PKG-INFO +18 -0
- codewords_client-0.1.0/codewords_client/__init__.py +117 -0
- codewords_client-0.1.0/codewords_client.egg-info/PKG-INFO +18 -0
- codewords_client-0.1.0/codewords_client.egg-info/SOURCES.txt +7 -0
- codewords_client-0.1.0/codewords_client.egg-info/dependency_links.txt +1 -0
- codewords_client-0.1.0/codewords_client.egg-info/requires.txt +4 -0
- codewords_client-0.1.0/codewords_client.egg-info/top_level.txt +1 -0
- codewords_client-0.1.0/setup.cfg +4 -0
- codewords_client-0.1.0/setup.py +24 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: codewords_client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Author: Sam Coope
|
|
5
|
+
Author-email: sam@agemo.ai
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Intended Audience :: Developers
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Requires-Dist: aiohttp
|
|
16
|
+
Requires-Dist: requests
|
|
17
|
+
Requires-Dist: websockets
|
|
18
|
+
Requires-Dist: codewords_core
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
import websockets
|
|
8
|
+
|
|
9
|
+
# add ../ to sys.path
|
|
10
|
+
from codewords_core.io_metadata import InputOutputMetadata
|
|
11
|
+
from codewords_core.file_type_utils import download_files_and_update_variables, upload_files_and_update_variables
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
WS_URL = os.environ['CWR_WS_URL']
|
|
15
|
+
HTTPS_URL = os.environ['CWR_HTTPS_URL']
|
|
16
|
+
except KeyError as e:
|
|
17
|
+
print(f"Environment variable {e} not set")
|
|
18
|
+
sys.exit(1)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def cw_function(
|
|
22
|
+
function_id: str,
|
|
23
|
+
version: str,
|
|
24
|
+
auth_data: dict,
|
|
25
|
+
runner_id: str,
|
|
26
|
+
**init_kwargs
|
|
27
|
+
) -> 'CWFunction':
|
|
28
|
+
resp = requests.post(
|
|
29
|
+
HTTPS_URL,
|
|
30
|
+
json={
|
|
31
|
+
"action": "get_info",
|
|
32
|
+
"function_id": function_id,
|
|
33
|
+
"version": version,
|
|
34
|
+
"auth_data": auth_data,
|
|
35
|
+
"runner_id": runner_id,
|
|
36
|
+
},
|
|
37
|
+
)
|
|
38
|
+
resp.raise_for_status()
|
|
39
|
+
definition_dict = resp.json()
|
|
40
|
+
|
|
41
|
+
inputs_metadata = [InputOutputMetadata.parse_obj(input_data) for input_data in definition_dict['inputs']]
|
|
42
|
+
outputs_metadata = [InputOutputMetadata.parse_obj(output_data) for output_data in definition_dict['outputs']]
|
|
43
|
+
return CWFunction(
|
|
44
|
+
definition_dict,
|
|
45
|
+
inputs_metadata,
|
|
46
|
+
outputs_metadata,
|
|
47
|
+
auth_data=auth_data,
|
|
48
|
+
runner_id=runner_id,
|
|
49
|
+
**init_kwargs
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class CWFunction():
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
definition_dict,
|
|
57
|
+
inputs_metadata,
|
|
58
|
+
outputs_metadata,
|
|
59
|
+
*,
|
|
60
|
+
working_directory='',
|
|
61
|
+
auth_data: dict,
|
|
62
|
+
runner_id: str,
|
|
63
|
+
verbose=False
|
|
64
|
+
):
|
|
65
|
+
self.definition_dict = definition_dict
|
|
66
|
+
self.inputs_metadata = inputs_metadata
|
|
67
|
+
self.outputs_metadata = outputs_metadata
|
|
68
|
+
self.working_directory = working_directory
|
|
69
|
+
self.auth_data = auth_data
|
|
70
|
+
self.runner_id = runner_id
|
|
71
|
+
self._print = print if verbose else lambda *args, **kwargs: None
|
|
72
|
+
|
|
73
|
+
async def run(self, inputs: Dict[str, Any]):
|
|
74
|
+
# find all the file type fields and upload them
|
|
75
|
+
inputs = await upload_files_and_update_variables(
|
|
76
|
+
variables=inputs,
|
|
77
|
+
variables_metadata=self.inputs_metadata,
|
|
78
|
+
working_directory=self.working_directory,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# call the lambda at WS_URL with an event
|
|
82
|
+
event = {
|
|
83
|
+
'action': 'run',
|
|
84
|
+
'function_id': self.definition_dict['function_id'],
|
|
85
|
+
'version': self.definition_dict['version'],
|
|
86
|
+
'inputs': inputs,
|
|
87
|
+
'runner_id': self.runner_id,
|
|
88
|
+
'auth_data': self.auth_data,
|
|
89
|
+
}
|
|
90
|
+
async with websockets.connect(WS_URL) as ws:
|
|
91
|
+
await ws.send(json.dumps(event))
|
|
92
|
+
|
|
93
|
+
# TODO - handle intermediate messages
|
|
94
|
+
response = await ws.recv()
|
|
95
|
+
response = json.loads(response)
|
|
96
|
+
|
|
97
|
+
if not response['type'] == 'run_complete':
|
|
98
|
+
raise ValueError(f"run didnt complete successfully: {response}")
|
|
99
|
+
|
|
100
|
+
outputs = response['outputs']
|
|
101
|
+
# download any files that were uploaded
|
|
102
|
+
outputs = await download_files_and_update_variables(
|
|
103
|
+
variables=outputs,
|
|
104
|
+
variables_metadata=self.outputs_metadata,
|
|
105
|
+
working_directory=self.working_directory,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
return outputs, response['run_info']
|
|
109
|
+
|
|
110
|
+
async def __call__(self, **inputs):
|
|
111
|
+
outputs, run_info = await self.run(inputs)
|
|
112
|
+
# if there's an error throw that
|
|
113
|
+
if len(run_info['error_messages']) > 0:
|
|
114
|
+
raise Exception(f"Run failed with error messages: {run_info['error_messages']}")
|
|
115
|
+
|
|
116
|
+
return outputs
|
|
117
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: codewords_client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Author: Sam Coope
|
|
5
|
+
Author-email: sam@agemo.ai
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Intended Audience :: Developers
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Requires-Dist: aiohttp
|
|
16
|
+
Requires-Dist: requests
|
|
17
|
+
Requires-Dist: websockets
|
|
18
|
+
Requires-Dist: codewords_core
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
codewords_client
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
with open('requirements.txt') as f:
|
|
4
|
+
required = f.read().splitlines()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name='codewords_client',
|
|
8
|
+
version='0.1.0',
|
|
9
|
+
author='Sam Coope',
|
|
10
|
+
author_email='sam@agemo.ai',
|
|
11
|
+
packages=find_packages(),
|
|
12
|
+
install_requires=required,
|
|
13
|
+
classifiers=[
|
|
14
|
+
'Development Status :: 3 - Alpha',
|
|
15
|
+
'Intended Audience :: Developers',
|
|
16
|
+
'License :: OSI Approved :: MIT License', # Replace with your license
|
|
17
|
+
'Programming Language :: Python :: 3',
|
|
18
|
+
'Programming Language :: Python :: 3.9',
|
|
19
|
+
'Programming Language :: Python :: 3.10',
|
|
20
|
+
'Programming Language :: Python :: 3.11',
|
|
21
|
+
'Programming Language :: Python :: 3.12',
|
|
22
|
+
],
|
|
23
|
+
python_requires='>=3.10'
|
|
24
|
+
)
|