fastiot.db package

Helpers for database connectivity will help to create a database connection using the environment variables set in your deployment.

Submodules

fastiot.db.influxdb_helper_fn module

class fastiot.db.influxdb_helper_fn.Client[source]

Singleton for Async InfluxDB Client

client = None
async fastiot.db.influxdb_helper_fn.get_async_influxdb_client_from_env()[source]

For connecting Influxdb, the environment variables can be set, if you want to use your own settings instead of default: FASTIOT_INFLUX_DB_HOST, FASTIOT_INFLUX_DB_PORT, FASTIOT_INFLUX_DB_TOKEN

After setting up the InfluxDB Server, the InfluxDB Server provides the possibility to visualize data in this database using browser with “http:<host>:<port>”. Default username: influx_db_admin and password: mf9ZXfeLKuaL3HL7w. You can also change these default values by editing FASTIOT_INFLUX_DB_USER and FASTIOT_INFLUX_DB_PASSWORD.

>>> influxdb_client = await get_async_influxdb_client_from_env()
async fastiot.db.influxdb_helper_fn.get_new_async_influx_client_from_env()[source]

Instead of using the singleton like in get_async_influxdb_client_from_env() a new connection to the database will be established. This seems to be necessary in some test cases.

async fastiot.db.influxdb_helper_fn.create_async_influxdb_client_from_env()[source]
async fastiot.db.influxdb_helper_fn.influx_query(machine, name, start_time, end_time)[source]
fastiot.db.influxdb_helper_fn.influx_query_wrapper(coro, *args)[source]

fastiot.db.mariadb_helper_fn module

fastiot.db.mariadb_schema_checks module

fastiot.db.mariadb_schema_checks.check_is_enum_represented(connection, sql_query, enum)[source]

Checks if enum values are in database table. The query must select a single column table with the enum values.

Raises:

SQLSchemaCheckError – raised if an enum is missing.

fastiot.db.mongodb_helper_fn module

class fastiot.db.mongodb_helper_fn.MongoClientWrapper(db_host, db_port, db_user=None, db_password=None, db_auth_source=None, db_compression=None)[source]
__init__(db_host, db_port, db_user=None, db_password=None, db_auth_source=None, db_compression=None)[source]

Constructor for a customer mongo client. Please note, that it will also set the feature compatibility version to the current mongodb version which may cause the database to be harder to downgrade.

Note: You have to manually install pymongo>=4.1,<5 using your requirements.txt to make use of this helper. Database clients are not automatically installed to keep the containers smaller.

get_client()[source]
fastiot.db.mongodb_helper_fn.get_mongodb_client_from_env()[source]

For connecting Mongodb, the environment variables can be set, if you want to use your own settings instead of default: FASTIOT_MONGO_DB_HOST, FASTIOT_MONGO_DB_PORT, FASTIOT_MONGO_DB_USER, FASTIOT_MONGO_DB_PASSWORD, FASTIOT_MONGO_DB_AUTH_SOURCE, FASTIOT_MONGO_DB_NAME

>>> mongo_client = get_mongodb_client_from_env()
fastiot.db.mongodb_helper_fn.time_series_data_to_mongodb_data_set(time_series_data)[source]
Return type:

Dict

fastiot.db.mongodb_helper_fn.time_series_data_from_mongodb_data_set(data_set)[source]
Return type:

TimeSeriesData

fastiot.db.redis_helper module

class fastiot.db.redis_helper.RedisClient[source]
client = None
async fastiot.db.redis_helper.connect_redis()[source]
async fastiot.db.redis_helper.get_redis_client()[source]
class fastiot.db.redis_helper.RedisHelper(broker_connection)[source]

Saves files in the redis Database and sends the ID of the files as fastiot.msg.redis.RedisMsg.

You can send files by using send_data() you must specify the data to send and the subject under which the data should be published. The max number of Datasets you can store at once is specified by :var: max_data_sets . If you add a Dataset above the given limit the first Dataset stored is deleted. When you have problems that an ID is overwritten before you accessed the data you can change the :var:`id_buffer` to have more Ids before an ID is reused.

You can access the stored data with get_data(). The Id of the Data has to be provided. and the returned data will be deserialized with fastiot.core.serialization.serialize_from_bin().

See also

fastiot_sample_services.redis_producer

Example service for sending and receiving data over a Redis Server.

fastiot.cli.common.infrastructure_services.RedisService

The infrastructure service definition for the Redis Server.

__init__(broker_connection)[source]
max_data_sets

The max number of Datasets you can store at once

id_buffer

:var:`max_data_sets` * :var:`id_buffer` is the total number of Ids, used before an id is overwritten

async send_data(data, subject)[source]
async get_data(address)[source]
async delete()[source]
async deleteall()[source]

fastiot.db.time_scale_helper_fn module

fastiot.db.time_scale_helper_fn.get_timescaledb_client_from_env()[source]

For connecting TimeScaleDB, the environment variables can be set, if you want to use your own settings instead of default: FASTIOT_TIME_SCALE_DB_HOST, FASTIOT_TIME_SCALE_DB_PORT, FASTIOT_TIME_SCALE_DB_USER, FASTIOT_TIME_SCALE_DB_PASSWORD, FASTIOT_TIME_SCALE_DB_DATABASE

>>> time_scale_db_client = get_timescaledb_client_from_env()
fastiot.db.time_scale_helper_fn.get_timescaledb_client(host, port, user, password, database=None)[source]