MCPcopy Index your code
hub / github.com/algorithmiaio/algorithmia-python / Algorithm

Class Algorithm

Algorithmia/algorithm.py:17–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17class Algorithm(object):
18 def __init__(self, client, algoRef):
19 # Parse algoRef
20 algoRegex = re.compile(r"(?:algo://|/|)(\w+/.+)")
21 m = algoRegex.match(algoRef)
22 if m is not None:
23 self.client = client
24 self.path = m.group(1)
25 self.username = self.path.split("/")[0]
26 self.algoname = self.path.split("/")[1]
27 if len(self.path.split("/")) > 2:
28 self.version = self.path.split("/")[2]
29 self.url = '/v1/algo/' + self.path
30 self.query_parameters = {}
31 self.output_type = OutputType.default
32 else:
33 raise ValueError('Invalid algorithm URI: ' + algoRef)
34
35 def set_options(self, timeout=300, stdout=False, output=OutputType.default, **query_parameters):
36 self.query_parameters = {'timeout': timeout, 'stdout': stdout}
37 self.output_type = output
38 self.query_parameters.update(query_parameters)
39 return self
40
41 def get_algorithm_id(self):
42 url = '/v1/algorithms/' + self.username + '/' + self.algoname
43 print(url)
44 api_response = self.client.getJsonHelper(url)
45 if 'id' in api_response:
46 return api_response['id']
47 else:
48 raise Exception("field 'id' not found in response: ", api_response)
49
50
51 def get_secrets(self):
52 algorithm_id = self.get_algorithm_id()
53 url = "/v1/algorithms/" + algorithm_id + "/secrets"
54 api_response = self.client.getJsonHelper(url)
55 return api_response
56
57
58 def set_secret(self, short_name, secret_key, secret_value, description=None):
59 algorithm_id = self.get_algorithm_id()
60 url = "/v1/algorithms/" + algorithm_id + "/secrets"
61 secret_providers = self.client.get_secret_providers()
62 provider_id = secret_providers[0]['id']
63
64 create_parameters = {
65 "owner_type": "algorithm",
66 "owner_id": algorithm_id,
67 "short_name": short_name,
68 "provider_id": provider_id,
69 "secret_key": secret_key,
70 "secret_value": secret_value,
71 }
72 if description:
73 create_parameters['description'] = description
74 else:

Callers 1

algoMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected