sticky_pi_api package¶
Subpackages¶
Submodules¶
sticky_pi_api.client module¶
Main module of the client. Implements classes to interact with the API.
-
class
sticky_pi_api.client.BaseClient(local_dir, n_threads=8, *args, **kwargs)[source]¶ Bases:
sticky_pi_api.specifications.BaseAPISpecAbstract class that defines the methods of the client (common between remote and client).
- Parameters
-
get_images_with_uid_annotations_series(info, what_image='metadata', what_annotation='metadata')[source]¶ Retrieves images alongside their annotations (if available) for images from a given device and within a given datetime range
- Parameters
info (
List[Dict[str,str]]) – A list of dicts. each dicts has, at least, the keys:'device','start_datetime'and'end_datetime'what_image (
str) – The nature of the image objects to retrieve. One of {'metadata','image','thumbnail','thumbnail_mini'}what_annotation (
str) – The nature of the object to retrieve. One of {'metadata','json'}.
- Return type
- Returns
A list of dictionaries with one element for each queried value. Each dictionary contains the fields present in the underlying database tables (see
UIDAnnotationsandImages).
-
get_uid_annotations_series(info, what='metadata')[source]¶ Retrieves annotations for images within a given datetime range
- Parameters
- Return type
- Returns
A list of dictionaries with one element for each queried value. Each dictionary contains the fields present in the underlying database table (see
UIDAnnotations). In the case ofwhat='metadata', the fieldjson=''. Otherwise, it contains a json string with the actual annotation data.
-
property
local_dir¶
-
class
sticky_pi_api.client.LocalClient(local_dir, n_threads=8, *args, **kwargs)[source]¶ Bases:
sticky_pi_api.client.BaseClient,sticky_pi_api.specifications.LocalAPIAbstract class that defines the methods of the client (common between remote and client).
sticky_pi_api.configuration module¶
sticky_pi_api.image_parser module¶
-
class
sticky_pi_api.image_parser.ImageParser(file)[source]¶ Bases:
dictA class derived from dict that contains image metadata in its fields. It parses data from an input JPEG image file taken by a Sticky Pi and retrieves its metadata from filename an exif fields. In addition, it computes md5 sum and generate thumbnails for the input image. :param file: path to file or file like object
-
property
file_blob¶
-
property
filename¶
-
property
thumbnail¶
-
property
thumbnail_mini¶
-
property
sticky_pi_api.specifications module¶
-
class
sticky_pi_api.specifications.BaseAPI(api_conf, *args, **kwargs)[source]¶ Bases:
sticky_pi_api.specifications.BaseAPISpec-
get_image_series(info, what='metadata')[source]¶ Retrieves image sequences (i.e. series). A series contains all images from a given device within a datetime range.
- Parameters
info (
List[Dict[str,Union[float,int,str]]]) – A list of dicts. each dicts has, at least, the keys:'device','start_datetime'and'end_datetime'.deviceis interpreted to the MySQL like operator. For instance,one can match all devices withdevice="%".what (
str) – The nature of the objects to retrieve. One of {'metadata','image','thumbnail','thumbnail_mini'}
- Returns
A list of dictionaries with one element for each queried value. Each dictionary contains the fields present in the underlying database plus a
'url'fields to retrieve the actual object requested (i.e. thewhat) argument. In the case ofwhat='metadata',url=''(i.e. no url is generated).
-
get_images(info, what='metadata')[source]¶ Retrieves information about a given set of images, defined by their parent device and the datetime of the picture. If an image is not available, no data is returned for this image.
- Parameters
- Returns
A list of dictionaries with one element for each queried value. Each dictionary contains the fields present in the underlying database plus a
'url'fields to retrieve the actual object requested (i.e. thewhat) argument. In the case ofwhat='metadata',url=''(i.e. no url is generated).
-
get_uid_annotations(info, what='metadata')[source]¶ Reteives annotations for a given set of images.
- Parameters
- Returns
A list of dictionaries with one element for each queried value. Each dictionary contains the fields present in the underlying database table (see
UIDAnnotations). In the case ofwhat='metadata', the fieldjson=''. Otherwise, it contains a json string with the actual annotation data.
-
get_users(info=None)[source]¶ Get a list of API users. Either all users (Default), or filter users by field if
infois specified. In the latter case, the union of all matched users is returned.- Parameters
info (
Optional[Dict[str,str]]) – A dictionary acting as a filter, using an SQL like-type match. For instance{'username': '%'}return all users.- Return type
- Returns
A list of users as represented in the underlying database, as one dictionary [per user, with the keys being database column names. Note that the crypo/sensitive fields are not returned (e.g. password_hash)
-
put_uid_annotations(info)[source]¶ - Parameters
info (
List[Dict[str,Union[List,Dict[str,Any]]]]) –A list of dictionaries corresponding to annotations (one list element per image). The annotations are formatted as a dictionaries with two keys:
'annotations'and'metadata'.'metadata'must have the fields:'algo_name': the name of the algorithm used to find the object (e.g.'sticky-pi-universal-insect-detector')'algo_version': The version of the algorithm as timestamp-md5 (e.g.'1598113346-ad2cd78dfaca12821046dfb8994724d5')'device': The device that took the annotated image (e.g.'5c173ff2')'datetime': The datetime at which the image was taken (e.g.'2020-06-20_21-33-24')'md5': The md5 of the image that was analysed (e.g.'9e6e908d9c29d332b511f8d5121857f8')
'annotations'is a list where each element represent an object. It has the fields:'contour': a 3d array encoding the position of the vertices (as convention in OpenCV)'name': the name/type of the object (e.g.'insect')'fill_colour'and'stroke_colour': the colours of the contour (if it is to be drawn – e.g.'#0000ff')'value': an optional integer further describing the contour (e.g.1)
- Returns
The metadata of the uploaded annotations (i.e. a list od dicts. each field of the dict naming a column in the database). This corresponds to the annotation data as represented in
UIDAnnotations
-
-
class
sticky_pi_api.specifications.BaseAPISpec[source]¶ Bases:
object-
get_image_series(info, what='metadata')[source]¶ Retrieves image sequences (i.e. series). A series contains all images from a given device within a datetime range.
- Parameters
info – A list of dicts. each dicts has, at least, the keys:
'device','start_datetime'and'end_datetime'.deviceis interpreted to the MySQL like operator. For instance,one can match all devices withdevice="%".what (
str) – The nature of the objects to retrieve. One of {'metadata','image','thumbnail','thumbnail_mini'}
- Return type
- Returns
A list of dictionaries with one element for each queried value. Each dictionary contains the fields present in the underlying database plus a
'url'fields to retrieve the actual object requested (i.e. thewhat) argument. In the case ofwhat='metadata',url=''(i.e. no url is generated).
-
get_images(info, what='metadata')[source]¶ Retrieves information about a given set of images, defined by their parent device and the datetime of the picture. If an image is not available, no data is returned for this image.
- Parameters
- Return type
- Returns
A list of dictionaries with one element for each queried value. Each dictionary contains the fields present in the underlying database plus a
'url'fields to retrieve the actual object requested (i.e. thewhat) argument. In the case ofwhat='metadata',url=''(i.e. no url is generated).
-
get_uid_annotations(info, what='metadata')[source]¶ Reteives annotations for a given set of images.
- Parameters
- Return type
- Returns
A list of dictionaries with one element for each queried value. Each dictionary contains the fields present in the underlying database table (see
UIDAnnotations). In the case ofwhat='metadata', the fieldjson=''. Otherwise, it contains a json string with the actual annotation data.
-
get_users(info=None)[source]¶ Get a list of API users. Either all users (Default), or filter users by field if
infois specified. In the latter case, the union of all matched users is returned.- Parameters
info (
Optional[Dict[str,str]]) – A dictionary acting as a filter, using an SQL like-type match. For instance{'username': '%'}return all users.- Return type
- Returns
A list of users as represented in the underlying database, as one dictionary [per user, with the keys being database column names. Note that the crypo/sensitive fields are not returned (e.g. password_hash)
-
put_uid_annotations(info)[source]¶ - Parameters
info (
List[Dict[str,Union[List,Dict[str,Any]]]]) –A list of dictionaries corresponding to annotations (one list element per image). The annotations are formatted as a dictionaries with two keys:
'annotations'and'metadata'.'metadata'must have the fields:'algo_name': the name of the algorithm used to find the object (e.g.'sticky-pi-universal-insect-detector')'algo_version': The version of the algorithm as timestamp-md5 (e.g.'1598113346-ad2cd78dfaca12821046dfb8994724d5')'device': The device that took the annotated image (e.g.'5c173ff2')'datetime': The datetime at which the image was taken (e.g.'2020-06-20_21-33-24')'md5': The md5 of the image that was analysed (e.g.'9e6e908d9c29d332b511f8d5121857f8')
'annotations'is a list where each element represent an object. It has the fields:'contour': a 3d array encoding the position of the vertices (as convention in OpenCV)'name': the name/type of the object (e.g.'insect')'fill_colour'and'stroke_colour': the colours of the contour (if it is to be drawn – e.g.'#0000ff')'value': an optional integer further describing the contour (e.g.1)
- Return type
- Returns
The metadata of the uploaded annotations (i.e. a list od dicts. each field of the dict naming a column in the database). This corresponds to the annotation data as represented in
UIDAnnotations
-
sticky_pi_api.storage module¶
-
class
sticky_pi_api.storage.BaseStorage(api_conf, *args, **kwargs)[source]¶ Bases:
object-
get_ml_bundle_file_list(bundle_name, what='all')[source]¶ List and describes the files present in a ML bundle.
- Parameters
- Return type
- Returns
A list of dict containing the fields
keyandurlof the files to be downloaded, which can be used to download the files
-
get_ml_bundle_upload_links(bundle_name, info)[source]¶ Request a list of upload links to put files in a given ML bundle
- Parameters
- Return type
- Returns
A list like
infowith the extra keyurlpointing to a destination where the file can be copied/posted. The list contains only files that did not exist on remote – hence can be empty.
-
-
class
sticky_pi_api.storage.DiskStorage(api_conf, *args, **kwargs)[source]¶ Bases:
sticky_pi_api.storage.BaseStorage-
get_ml_bundle_file_list(bundle_name, what='all')[source]¶ List and describes the files present in a ML bundle.
- Parameters
- Return type
- Returns
A list of dict containing the fields
keyandurlof the files to be downloaded, which can be used to download the files
-
get_ml_bundle_upload_links(bundle_name, info)[source]¶ Request a list of upload links to put files in a given ML bundle
- Parameters
- Return type
- Returns
A list like
infowith the extra keyurlpointing to a destination where the file can be copied/posted. The list contains only files that did not exist on remote – hence can be empty.
-
sticky_pi_api.types module¶
sticky_pi_api.utils module¶
Module contents¶
this is the __init__ of sticky_pi_api