-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy path__init__.py
More file actions
55 lines (44 loc) · 1.6 KB
/
Copy path__init__.py
File metadata and controls
55 lines (44 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'Algorithmia API Client (python)'
from Algorithmia.client import Client
from Algorithmia.handler import Handler
import sys
import sys
if sys.version_info[0] >= 3:
from adk import ADK
import os
apiKey = None
apiAddress = None
# Get reference to an algorithm using a default client
def algo(algoRef):
# Return algorithm reference using default client
return getDefaultClient().algo(algoRef)
def file(dataUrl):
return getDefaultClient().file(dataUrl)
def dir(dataUrl):
return getDefaultClient().dir(dataUrl)
def client(api_key=None, api_address=None, ca_cert=None, bearer_token=None):
return Client(api_key, api_address, ca_cert, bearer_token)
def handler(apply_func, load_func=lambda: None):
return Handler(apply_func, load_func)
# The default client to use, assuming the user does not want to construct their own
defaultClient = None
# Used internally to get default client
def getDefaultClient():
global defaultClient
# Check for default client, and ensure default API key has not changed
if defaultClient is None or defaultClient.apiKey is not apiKey:
# Construct default client
defaultClient = Client(apiKey)
return defaultClient
# Used internally to get default api client
def getApiAddress():
global apiAddress
if apiAddress is not None:
# First check for user setting Algorithmia.apiAddress = "XXX"
return apiAddress
elif 'ALGORITHMIA_API' in os.environ:
# Then check for system environment variable
return os.environ['ALGORITHMIA_API']
else:
# Else return default
return "https://api.algorithmia.com"