Home

Awesome

SiriDB - Connector

The SiriDB Connector is a self-contained Python driver for communicating with SiriDB servers. This manual describes how to install and configure SiriDB Connector for Python 3, and how to use it to develop database applications.



Installation


From PyPI (recommended)

pip install siridb-connector

From source code

python setup.py install

Quick usage


import asyncio
import time
import random
from siridb.connector import SiriDBClient

async def example(siri):
    # Start connecting to SiriDB.
    # .connect() returns a list of all connections referring to the supplied
    # hostlist. The list can contain exceptions in case a connection could not
    # be made.
    await siri.connect()

    try:
        # insert
        ts = int(time.time())
        value = random.random()
        await siri.insert({'some_measurement': [[ts, value]]})

        # query
        resp = await siri.query('select * from "some_measurement"')
        print(resp)

    finally:
        # Close all SiriDB connections.
        siri.close()


siri = SiriDBClient(
    username='iris',
    password='siri',
    dbname='dbtest',
    hostlist=[('localhost', 9000)],  # Multiple connections are supported
    keepalive=True)

asyncio.run(example(siri))

SiriDBClient

Create a new SiriDB Client. This creates a new client but .connect() must be used to connect.

siri = SiriDBClient(
    username=<username>,
    password=<password>,
    dbname=<dbname>,
    hostlist=[(<host>, <port>, {weight: 1}, {backup: False})],
    loop=None,
    keepalive=True,
    timeout=10,
    inactive_time=30,
    max_wait_retry=90)

Arguments:

Keyword arguments:


SiriDBClient.connect

Start connecting to SiriDB. .connect() returns a list of all connections referring to the supplied hostlist. The list can contain exceptions in case a connection could not be made.

Optionally the keyword argument timeout can be set. This will constrain the search time for a connection. Exceeding the timeout will raise an .TimeoutError.

siri.connect(timeout=None)

SiriDBClient.insert

Insert time series data into SiriDB. Requires a 'dictionary' with at least one series. Optionally the timeout can be adjusted (default: 300).

siri.insert(data, timeout=300)

SiriDBClient.query

Query data out of the database. Requires a string containing the query. More about the query language can be found here. The documentation about the query language will inform you about a number of useful aggregation and filter functions, different ways of visualizing and grouping the requested data, and how to make changes to the set up of the database. Optionally a time_precision (SECOND, MICROSECOND, MILLISECOND, NANOSECOND) can be set. The default None sets the precision to seconds. Futhermore the timeout can be adjusted (default: 60).

from siridb.connector import (SECOND,
                              MICROSECOND,
                              MILLISECOND,
                              NANOSECOND)

siri.query(query, time_precision=None, timeout=60)

SiriDBClient.close

Close the connection.

siri.close()

Check if the connection is closed.

siri.is_closed

Exception codes

The following exceptions can be returned: