Welcome to wotkitpy’s documentation!
Contents: WoTKit API client written in Python.
Methods
A Python client for communicating to the WoTKit API using the requests library.
-
class wotkitpy.WotkitProxy(**kwargs)[source]
Acts as a network proxy to the WotKit based on the configuration supplied.
-
create_wotkit_user(data, username=None, password=None)[source]
Creates user given in data dictionary. Requires admin credentials in WotkitConfig
-
delete_data(sensor_id, timestamp, username=None, password=None)[source]
Delete all data corresponding with timestamp.
Parameters: |
- sensor_id (str.) – Sensor ID to delete data from.
- timestamp (int or str) – Timestamp in numeric UNIX timestamp or ISO form string.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
delete_sensor(sensor_id, username=None, password=None)[source]
Delete sensor from WoTKit.
Parameters: |
- sensor_id (str.) – Sensor ID to delete.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 204
|
-
delete_sensor_field(sensor_id, field_name, username=None, password=None)[source]
Delete sensor field.
Parameters: |
- sensor_id (str.) – Sensor ID to delete field.
- field_name (str) – Delete this field name. None of the default fields can be deleted (lat, lng, value, message).
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
get_aggregated_data(**kwargs)[source]
Get data from multiple sensors queried using the same parameters.
Parameters: |
- scope (str.) – “all”, “subscribed”, or “contributed”. “all” - all sensors the current user has access to. “subscribed” - the sensors the user has subscribed to. “contributed” - the sensors the user has contributed to the system.
- tags (str.) – list of comma separated tags.
- orgs (str.) – list of comma separated organization names.
- visibility (str.) – filter by the visibility of the sensors, either of “public”, “organization”, or “private”
- text (str.) – text to search for in the name, long name and description.
- active (bool.) – when true, only returns sensors that have been updated in the last 15 minutes.
- start (int) – the absolute start time of the range of data selected in milliseconds. (Defaults to current time.) May only be used in combination with another parameter.
- end (int) – the absolute end time of the range of data in milliseconds
- after (int) – the relative time after the start time, e.g. after=300000 would be 5 minutes after the start time (Start time MUST also be provided.)
- afterE (int) – the number of elements after the start element or time. (Start time MUST also be provided.)
- before (int) – the relative time before the start time. E.g. data from the last hour would be before=3600000 (If not provided, start time default to current time.)
- beforeE (int) – the number of elements before the start time. E.g. to get the last 1000, use beforeE=1000 (If not provided, start time default to current time.)
- orderBy (str) – “sensor” groups by sensor id or “time” orders by timestamp (default).
|
Raises : | WotkitException if a status code is not 200’s
|
Return type: | list of sensor data
|
-
get_formatted_data(sensor_id, **kwargs)[source]
Get formatted data from a WoTKit sensor suitable for Google Visualizations.
Parameters: | sensor_id (str.) – Sensor ID to get data from. |
Same parameters as get_raw_data. Additionally:
Parameters: |
- tqx (str) – A set of colon-delimited key/value pairs for standard parameters
- tq (str) – A SQL clause to select and process data fields to return
|
Raises : | WotkitException if a status code is not 200’s
|
Return type: | str that is javascript
|
-
get_raw_data(sensor_id, **kwargs)[source]
Get raw data from a WoTKit sensor.
Parameters: |
- sensor_id (str.) – Sensor ID to get data from.
- start (int) – the absolute start time of the range of data selected in milliseconds. (Defaults to current time.) May only be used in combination with another parameter.
- end (int) – the absolute end time of the range of data in milliseconds
- after (int) – the relative time after the start time, e.g. after=300000 would be 5 minutes after the start time (Start time MUST also be provided.)
- afterE (int) – the number of elements after the start element or time. (Start time MUST also be provided.)
- before (int) – the relative time before the start time. E.g. data from the last hour would be before=3600000 (If not provided, start time default to current time.)
- beforeE (int) – the number of elements before the start time. E.g. to get the last 1000, use beforeE=1000 (If not provided, start time default to current time.)
- reverse (bool) – true: order the data from newest to oldest; false (default):order from oldest to newest
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
Return type: | list of sensor data
|
-
get_sensor_by_id(sensor_id, username=None, password=None)[source]
Get a sensor by ID.
Parameters: |
- sensor_id (str.) – Sensor ID to get.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Return type: | dict representing sensor data, or None if sensor does not exist.
|
Raises : | WotkitException if a status code is not 200 or 404
|
-
get_sensor_by_name(sensor_name, username=None, password=None)[source]
Get a sensor by name.
Parameters: |
- sensor_name (str.) – Sensor name to get (no username component prepended, ie. if the full name is admin.sensor_name, use sensor_name).
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Return type: | dict representing sensor data, or None if sensor does not exist.
|
Raises : | WotkitException if a status code is not 200 or 404
|
-
get_sensor_fields(sensor_id, field_name=None, username=None, password=None)[source]
Get sensor fields.
Parameters: |
- sensor_id (str.) – Sensor ID to get fields.
- field_name (str) – If specified, only gets this field name.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
Return type: | list of sensor fields, or dict of sensor field if field_name was specified
|
-
get_sensor_subscriptions(username=None, password=None)[source]
View sensors that user is subscribed to.
Parameters: |
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
Return type: | list of sensors subscribed
|
-
get_wotkit_user(user_id, username=None, password=None)[source]
Get wotkit user with user_id. Requires admin credentials in WotkitConfig
-
query_actuator(subscription_id, wait_time, **kwargs)
Query actuator
Parameters: |
- subscription_id (str.) – Subscription ID for actuator
- wait_time (int) – Seconds to wait for message, Max 20.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
Return type: | dict of control messages
|
-
query_all_sensors(**kwargs)[source]
Searches all sensors that match the search query. A wrapper function on top of query_sensors that performs multiple API calls to retrieve all matches for search results more than 1000 sensors.
Note
When multiple API calls are made the search result could potentially be off sync with the WoTKit due to updates occuring to the sensors as the search is being performed.
Parameters: |
- scope (str.) – “all”, “subscribed”, or “contributed”. “all” - all sensors the current user has access to. “subscribed” - the sensors the user has subscribed to. “contributed” - the sensors the user has contributed to the system.
- tags (str.) – list of comma separated tags.
- orgs (str.) – list of comma separated organization names.
- visibility (str.) – filter by the visibility of the sensors, either of “public”, “organization”, or “private”
- text (str.) – text to search for in the name, long name and description.
- active (bool.) – when true, only returns sensors that have been updated in the last 15 minutes.
- location (str.) – geo coordinates for a bounding box to search within. Format is yy.yyy,xx.xxx:yy.yyy,xx.xxx, and the order of the coordinates are North,West:South,East. Example: location=56.89,-114.55:17.43,-106.219.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Return type: | list of dict’s containing each sensor’s data. Empty list of no matches.
|
Raises : | WotkitException if a status code is not 200’s
|
-
query_sensors(**kwargs)[source]
Searches sensors that match the search query.
Parameters: |
- scope (str.) – “all”, “subscribed”, or “contributed”. “all” - all sensors the current user has access to. “subscribed” - the sensors the user has subscribed to. “contributed” - the sensors the user has contributed to the system.
- tags (str.) – list of comma separated tags.
- orgs (str.) – list of comma separated organization names.
- visibility (str.) – filter by the visibility of the sensors, either of “public”, “organization”, or “private”
- text (str.) – text to search for in the name, long name and description.
- active (bool.) – when true, only returns sensors that have been updated in the last 15 minutes.
- location (str.) – geo coordinates for a bounding box to search within. Format is yy.yyy,xx.xxx:yy.yyy,xx.xxx, and the order of the coordinates are North,West:South,East. Example: location=56.89,-114.55:17.43,-106.219.
- offset (int.) – offset into list of sensors for paging.
- limit (int.) – limit to show for paging. The maximum number of sensors to display is 1000.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
register_multiple_sensors(registration_list, username=None, password=None)[source]
Registers multiple new sensor to the WoTKit. If there are more than 100 sensor’s in registration_list, performs multiple bulk registration requests to the WoTKit.
Parameters: |
- registration_list (list of dict) – A Python list that represents the JSON registration data. (ie. json.dumps(registration_dict) must not fail). For more detail look at register_sensor since the registration_list is just a list of single registration_dict’s.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
register_sensor(registration_dict, username=None, password=None)[source]
Registers a new sensor to the WoTKit.
Parameters: |
- registration_dict (dict.) – A Python dictionary that represents the JSON registration data. (ie. json.dumps(registration_dict) must not fail). “name”, “longName”, and “description” are required. “longitude”, “latitude” are optional and will default to 0. “visibility” is optional and will default to “public”, if it is “organization” a valid “organization” must be supplied. “tags”, “fields”, “organization” are optional. The sensor name must be at least 4 characters long, contain only lowercase letters, numbers, dashes and underscores, and can start with a lowercase letter or an underscore only.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
send_actuator_message(sensor_id, **kwargs)
Send actuator message to a sensor.
Parameters: |
- sensor_id (str.) – Sensor ID
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
send_bulk_data_put(sensor_id, data, username=None, password=None)[source]
Send multiple data dictionaries to WoTKit.
.. note:: data sent this way is not processed in real time.
Parameters: |
- sensor_id (str.) – Sensor ID to send data to.
- data (list of dict) – Data to send to this sensor. Compared with sending single new data by POST, each data item must contain a timestamp. The current timestamp can be obtained by calling get_wotkit_timestamp().
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
send_bulk_data_put_by_name(sensor_name, data, username=None, password=None)[source]
Wrapper around send_bulk_data_put that allows sending new data to a given sensor name .
Parameters: |
- sensor_name (str.) – Sensor name to send data to (no username component prepended, ie. if the full name is admin.sensor_name, use sensor_name).
- data (list of dict) – Data to send to this sensor. Compared with sending single new data by POST, each data item must contain a timestamp. The current timestamp can be obtained by calling get_wotkit_timestamp().
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
send_data_post(sensor_id, data, username=None, password=None)[source]
Send new data to a sensor.
Parameters: |
- sensor_id (str.) – Sensor ID to send data to.
- data (dict) – Data to send to this sensor.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
send_data_post_by_name(sensor_name, data, username=None, password=None)[source]
Wrapper around send_data_post that allows sending new data to a given sensor name .
Parameters: |
- sensor_name (str.) – Sensor name to send data to (no username component prepended, ie. if the full name is admin.sensor_name, use sensor_name).
- data (dict) – Data to send to this sensor.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
subscribe_actuator(sensor_id, **kwargs)
Subscribe to actuator.
Parameters: |
- sensor_id (str.) – Sensor ID
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
Return type: | dict containing subscription id
|
-
subscribe_sensor(sensor_id, username=None, password=None)[source]
Subscribe to sensor for user.
Parameters: |
- sensor_id (str.) – Sensor ID to subscribe.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
unsubscribe_sensor(sensor_id, username=None, password=None)[source]
Unsubscribe sensor for user.
Parameters: |
- sensor_id (str.) – Sensor ID to unsubscribe.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
update_sensor(sensor_id, update_dict, username=None, password=None)[source]
Updates a sensor on the WoTKit.
Parameters: |
- sensor_id (str.) – Sensor ID to update.
- update_dict (dict.) – A Python dictionary that represents the JSON update data. (ie. json.dumps(update_dict) must not fail). Look at registration for more details. Updating a sensor is the same as registering a new sensor other than PUT is used and the sensor name or id is included in the URL.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
update_sensor_field(sensor_id, field_name, field_data, username=None, password=None)[source]
Update sensor field.
Parameters: |
- sensor_id (str.) – Sensor ID to update field.
- field_name (str) – Updates this field name. If it doesn’t exist, it creates a new field.
- field_data (dict) – Field data. “name” and “type” are required “name” in an existing field cannot be updated.
- username (str.) – If provided with password, overrides the default login credentials supplied on initialization.
- password (str.) – Used in combination with username.
|
Raises : | WotkitException if a status code is not 200’s
|
-
update_wotkit_user(user_id, data, username=None, password=None)[source]
Updates user user_id with data dictionary. Requires admin credentials in WotkitConfig
-
wotkitpy.get_wotkit_timestamp()[source]
Returns the current timestamp in the format WoTKit recognizes.