API Documentation¶
Constants¶
-
iotrelay.
version
¶ The version number of the iotrelay module, as a string.
-
iotrelay.
DEFAULT_CONFIG
¶ The configuration file name and path to use if one is not specified.
-
iotrelay.
GROUP
¶ The setuptools group to inspect for available plugins.
Classes¶
-
class
iotrelay.
Reading
(reading_type, value[, timestamp[, series_key[, tags]]])[source]¶ Reading provides a container for passing a datum, or “Reading”, between sources and handlers.
-
reading_type
¶ represents a category of readings. For example, a weather station might produce temperature, rainfall, and wind speed. Because all of these are related to weather, they could be categorized with a reading type of “weather”.
reading_type
is used to match data sources with data handlers. If a data source generates readings with areading_type
of weather, data handlers that have registered an interest in weather will receive those readings.
-
value
¶ contains the datum being communicated.
-
timestamp
¶ A a
datetime
object containing the time stamp at which the reading was taken.If timestamp is not specified in the constructor, timestamp is set to the time the
Reading
object was created.
-
series_key
¶ identifies an individual time series. A weather station may produce multiple data streams, one for each sensor. Each of these streams should have their own series key.
If a
series_key
is not specified in the constructor,series_key
is set toreading_type
.
a dictionary of key value pairs, describing the reading.
-
-
class
iotrelay.
DataSource
(config)¶ DataSource is an abstract class for implementing data source plugins.
-
config
¶ A dict containing key/value pairs corresponding to options taken from the plugin’s section in iotrelay’s config file,
~/.iotrelay.cfg
.
-
get_readings
()¶ Get readings from a data source.
Returns: one or more Readings or no Reading
Return type: Reading
, an iterable ofReading
instances, or None
Example Data Source:
# source/iotrelay_sample_source.py import random from iotrelay import Reading class DataSource(object): def __init__(self, config): self.config = config def get_readings(self): value = random.randint(1, 100) return Reading(reading_type='random', value=value)
-
-
class
iotrelay.
Handler
(config)¶ Handler is an abstract class for implementing data handler plugins.
-
config
¶ A dict containing key/value pairs corresponding to options taken from the plugin’s section in iotrelay’s config file,
~/.iotrelay.cfg
.
-
set_reading
(reading)¶ Send a reading to a handler.
Parameters: reading (iotrelay.Reading) – The Reading instance being sent to the handler.
-
flush
()¶ Optional: Flush any readings that have not been sent or otherwise processed.
Example Data Handler:
# handler/iotrelay_sample_handler.py class Handler(object): def __init__(self, config): self.config = config def set_reading(self, reading): print(reading)
-