voxel51 / api-py Goto Github PK
View Code? Open in Web Editor NEWPython Client Library for the Voxel51 Platform
License: BSD 4-Clause "Original" or "Old" License
Python Client Library for the Voxel51 Platform
License: BSD 4-Clause "Original" or "Old" License
We could support creating API sessions by simply setting an VOXEL51_API_KEY
environment variable that contains only one's private key, rather than forcing the user to have the entire token on disk, pointed to by VOXEL51_API_TOKEN
This simple job request does not result in a started job:
job_request = JobRequest("vehicle-tracker")
job_request.set_input("file", data_id=data_id)
job_request.set_parameter("job_name", "tracker-test")
job_request.set_parameter("auto_start", True)
TokenLoadError is defined in voxel51/auth.py
but missing from voxel51/apps/auth.py
As a scoop application, we currently have to iterate through each user individually to request information regarding jobs and data. It would be nice to request all jobs for all users of the application or batch query a list of job ids.
from voxel51.api import API
api = API()
api.upload_analytic("/path/to/analytic.json")
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-4-1f6d68783277> in <module>
----> 1 api.upload_analytic("/path/to/analytic.json")
~/api-py/voxel51/api.py in upload_analytic(self, doc_json_path)
162 '''
163 endpoint = self.base_url + "analytics"
--> 164 filename = os.path.basename(path)
165 mime_type = _get_mime_type(doc_json_path)
166 with open(doc_json_path, "rb") as df:
NameError: name 'path' is not defined
from voxel51.api import API
api = API()
api.upload_analytic("/path/to/analytic.json")
api.upload_analytic_image("analytic id", "/path/to/image.tar.gz", "gpu")
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
<ipython-input-9-2c6500bb68c5> in <module>
----> 1 api.upload_analytic_image("analytic id", "/path/to/image.tar.gz", "gpu")
~/api-py/voxel51/api.py in upload_analytic_image(self, analytic_id, image_tar_path, image_type)
191 files = {"file": (filename, df, mime_type)}
192 res = self._requests.post(
--> 193 endpoint, headers=self._header, files=files, params=params)
194 _validate_response(res)
195
~/myenv/lib/python3.5/site-packages/requests/api.py in post(url, data, json, **kwargs)
114 """
115
--> 116 return request('post', url, data=data, json=json, **kwargs)
117
118
~/myenv/lib/python3.5/site-packages/requests/api.py in request(method, url, **kwargs)
58 # cases, and look like a memory leak in others.
59 with sessions.Session() as session:
---> 60 return session.request(method=method, url=url, **kwargs)
61
62
~/myenv/lib/python3.5/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
522 }
523 send_kwargs.update(settings)
--> 524 resp = self.send(prep, **send_kwargs)
525
526 return resp
~/myenv/lib/python3.5/site-packages/requests/sessions.py in send(self, request, **kwargs)
635
636 # Send the request
--> 637 r = adapter.send(request, **kwargs)
638
639 # Total elapsed time of the request (approximately)
~/myenv/lib/python3.5/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
447 decode_content=False,
448 retries=self.max_retries,
--> 449 timeout=timeout
450 )
451
~/myenv/lib/python3.5/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
598 timeout=timeout_obj,
599 body=body, headers=headers,
--> 600 chunked=chunked)
601
602 # If we're going to release the connection in ``finally:``, then
~/myenv/lib/python3.5/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
352 conn.request_chunked(method, url, **httplib_request_kw)
353 else:
--> 354 conn.request(method, url, **httplib_request_kw)
355
356 # Reset the timeout for the recv() on the socket
/usr/lib/python3.5/http/client.py in request(self, method, url, body, headers)
1104 def request(self, method, url, body=None, headers={}):
1105 """Send a complete request to the server."""
-> 1106 self._send_request(method, url, body, headers)
1107
1108 def _set_content_length(self, body, method):
/usr/lib/python3.5/http/client.py in _send_request(self, method, url, body, headers)
1149 # default charset of iso-8859-1.
1150 body = _encode(body, 'body')
-> 1151 self.endheaders(body)
1152
1153 def getresponse(self):
/usr/lib/python3.5/http/client.py in endheaders(self, message_body)
1100 else:
1101 raise CannotSendHeader()
-> 1102 self._send_output(message_body)
1103
1104 def request(self, method, url, body=None, headers={}):
/usr/lib/python3.5/http/client.py in _send_output(self, message_body)
934 self.send(msg)
935 if message_body is not None:
--> 936 self.send(message_body)
937
938 def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0):
/usr/lib/python3.5/http/client.py in send(self, data)
906 return
907 try:
--> 908 self.sock.sendall(data)
909 except TypeError:
910 if isinstance(data, collections.Iterable):
/usr/lib/python3.5/ssl.py in sendall(self, data, flags)
889 count = 0
890 while (count < amount):
--> 891 v = self.send(data[count:])
892 count += v
893 return amount
/usr/lib/python3.5/ssl.py in send(self, data, flags)
859 "non-zero flags not allowed in calls to send() on %s" %
860 self.__class__)
--> 861 return self._sslobj.write(data)
862 else:
863 return socket.send(self, data, flags)
/usr/lib/python3.5/ssl.py in write(self, data)
584 The 'data' argument must support the buffer interface.
585 """
--> 586 return self._sslobj.write(data)
587
588 def getpeercert(self, binary_form=False):
OverflowError: string longer than 2147483647 bytes
In [1]: from voxel51.users.api import API
In [2]: api = API()
In [3]: analytics = api.list_analytics()
In [4]: len(analytics)
Out[4]: 35
In [5]: [a for a in analytics if a["name"] == "voxel51/road-sense"]
Out[5]:
[{'scope': 'public',
'id': 'ae1e82f5-23a8-456a-914c-dadd789bc6a4',
'name': 'voxel51/road-sense',
'version': '0.7.1'}]
In [6]: analytics = api.list_analytics(all_versions=True)
In [7]: len(analytics)
Out[7]: 35
In [8]: [a for a in analytics if a["name"] == "voxel51/road-sense"]
Out[8]:
[{'scope': 'public',
'id': 'ae1e82f5-23a8-456a-914c-dadd789bc6a4',
'name': 'voxel51/road-sense',
'version': '0.7.1'}]
from voxel51.api import API
api = API()
api.upload_analytic("/path/to/analytic.json")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-1f6d68783277> in <module>
----> 1 api.upload_analytic("/path/to/analytic.json")
~/api-py/voxel51/api.py in upload_analytic(self, doc_json_path)
168 res = self._requests.post(
169 endpoint, headers=self._header, files=files)
--> 170 _validate_response(res)
171 return _parse_json_response(res)["analytic"]
172
~/api-py/voxel51/api.py in _validate_response(res)
793 def _validate_response(res):
794 if not res.ok:
--> 795 raise APIError.from_response(res)
796
797
~/api-py/voxel51/api.py in from_response(cls, res)
780
781 try:
--> 782 message = _parse_json_response(res)["error"]["message"]
783 except ValueError:
784 res.raise_for_status()
~/api-py/voxel51/api.py in _parse_json_response(res)
797
798 def _parse_json_response(res):
--> 799 return json.loads(res.content)
/usr/lib/python3.5/json/__init__.py in loads(s, encoding, cls, object_hook, pars
e_float, parse_int, parse_constant, object_pairs_hook, **kw)
310 if not isinstance(s, str):
311 raise TypeError('the JSON object must be str, not {!r}'.format(
--> 312 s.__class__.__name__))
313 if s.startswith(u'\ufeff'):
314 raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-
sig)",
TypeError: the JSON object must be str, not 'bytes'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.