fastiot.msg package

Base package to hold any core message formats

Submodules

fastiot.msg.custom_db_data_type_conversion module

fastiot.msg.custom_db_data_type_conversion.to_mongo_data(timestamp, subject_name, msg)[source]

This function helps to convert msg to a mongodb data set.

Return type:

Dict

fastiot.msg.custom_db_data_type_conversion.from_mongo_data(mongo_data)[source]

This function helps to convert mongodb data set back to the msg.

Return type:

Dict

fastiot.msg.hist module

Messages handling queries to databases with historic data (time series or object storage)

pydantic model fastiot.msg.hist.HistObjectResp[source]

This Class is used to answer the request for historical data.

field error_code: int = 0

error number

Validated by:
field error_msg: str = ''

if an error occurred you can get a detailed description

Validated by:
field values: List[dict] [Required]

the results of the request

Validated by:
pydantic model fastiot.msg.hist.HistObjectReq[source]

This class is used for requesting historical data of your data type.

You can instance a HistObjectReq object like following:

query_dict = {'test_index': 'test'}
hist_object_req_msg = HistObjectReq(dt_start=dt_start, dt_end=dt_end, limit=10,
                                    subject_name=sanitize_subject('my_data_type'), raw_query=query_dict)

More details about sanitize_subject_name() see fastiot.core.subject_helper.sanitize_subject_name() This subject_name inside the HistObjectReq is the subject_name, that your data type has. Your data, which will be saved in mongodb, always contains this subject_name: ‘v1.my_data_type’.

After instancing HistObjectReq, a subject for requesting historical data must also be instanced, with the name ‘my_data_type’.

reply_subject = hist_object_req_msg.get_reply_subject('my_data_type')

Then you will have a ReplySubject object like:

>>> ReplySubject(name='v1.hist_object_req.my_data_type', msg_cls=HistObjectReq, reply_cls=HistObjectResp)
field dt_start: Optional[datetime] = None

is used to limit the time range.

Validated by:
field dt_end: Optional[datetime] = None

is used to limit the time range.

Validated by:
field limit: Optional[int] = 100

will limit the number of results.

Validated by:
field subject_name: Optional[str] = None

will search only the objects, which are saved under this subject_name. CAUTION! This is not the request-reply subject name.

Validated by:
field machine: Optional[str] = None

is used to return only the value of the given machine

Validated by:
field sensor: Optional[str] = None

is used to return only the value of the given sensor

Validated by:
field raw_query: Union[dict, str, None] = None

is an optional variable, you can also add your own query_dict, besides the default setting, which consists only _subject and _timestamp. Your default will be extended by query_dict, after ObjectStorage Service receives it. The handling of argument is subject to each service and may be handled different e.g. if using an InfluxDB time series storage or a MongoDB based object storage.

Validated by:

fastiot.msg.redis module

pydantic model fastiot.msg.redis.RedisMsg[source]
field id: str [Required]

Id the data is stored under

Validated by:

fastiot.msg.thing module

pydantic model fastiot.msg.thing.Thing[source]

Default data model for sending Things (e.g. Sensors) values.

This model expects a hierarchy, thus when subscribing always set the name to the sensor name you are looking for or to * to subscribe all sensors. See fastiot.core.data_models.FastIoTData.get_subject() for more details!.

field machine: str [Required]

Name of the machine. If you have many machines you may add the vendor to the machine name.

Validated by:
field name: str [Required]

Name of the thing or sensor.

Validated by:
field measurement_id: str = 'acb8ab5c-1740-11ee-b329-0242ac110002'

Measurement id for this thing or sensor. The measurement id is intended to be unique across a measurement. If the data producer is restarted, it should change. This can be useful e.g. if a measurement is messed up and needs to be removed. Per default a UUID will be generated upon system start for this property.

Validated by:
field value: Any = None

Any data type suitable for Pydantic and serializable by ormsgpack may be used. Be aware, that the receiving site needs no be able to cope with whatever you send.

We recommend to stick to int, float and string and create your own data models based on fastiot.core.subject.FastIoTData if want to sent more advanced data.

Validated by:
field timestamp: datetime [Required]

Timestamp for the value.

It is recommended to always use UTC times (Function datetime.utcnow()).

Validated by:
field unit: str = ''

Optional add a unit, e.g. ‘s’ to the measurement.

Validated by:
property default_subject: Subject

Returns a default subject for this thing to be published on. For more fine-grained behavior, please consider using get_subject instead.

fastiot.msg.time_series_msg module

pydantic model fastiot.msg.time_series_msg.TimeSeriesData[source]
field id: str [Required]
Validated by:
field name: str [Required]
Validated by:
field service_id: str [Required]
Validated by:
field measurement_id: str [Required]
Validated by:
field dt_start: datetime [Required]
Validated by:
field dt_end: datetime [Required]
Validated by:
field modified_at: datetime [Required]
Validated by:
field values: Any = None
Validated by:
to_dict()[source]
Return type:

Dict

static from_dict(timeseries_dict)[source]
Return type:

TimeSeriesData