Skip to the content.

Influxable logo

Influxable

PyPI version Build status Code coverage License: MIT

A lightweight Python ORM / ODM / Client for InfluxDB

Table of Contents

Note

This project is currently in development.

A better documentation and testing scripts will be added in the next release.

Genesis

I worked on a project with InfluxDB. I needed to build an API for InfluxDB and to plug with Python libraries (scipy, pandas, etc …).

That’s why I decided to create this repository in order to deal with InfluxDB in a smooth way and to manipulate Python object.

Changelog

1.4.0

1.3.0

1.2.1

Features

Dependencies

Installation

The package is available on PyPI. You can install it via pip:

pip install influxable

Getting started

Connection

You can set your environment variable for the connection of InfluxDB in order to override the default values:

INFLUXDB_URL=http://localhost:8086
INFLUXDB_DATABASE_NAME=default

# Optional
INFLUXDB_USER=admin
INFLUXDB_PASSWORD=changme

# OSS 2.0
INFLUXDB_AUTH_TOKEN=mytoken

Then you just have to import the influxable package and create an instance of Influxable:

from influxable import Influxable

client = Influxable()

You can also set connection variable in Influxable constructor:

# Without authentication
client = Influxable(
    base_url='http://localhost:8086',
    database_name='default',
)

# With authentication
client = Influxable(
    base_url='http://localhost:8086',
    database_name='default',
    user='admin',
    password='changeme',
)

# With token authentication
client = Influxable(
    base_url='http://localhost:8086',
    database_name='default',
    token='my_token',
)

Measurement

from influxable import attributes, serializers
from influxable.measurement import Measurement

class TemperatureMeasurement(Measurement):
    parser_class = serializers.MeasurementPointSerializer  # Default
    measurement_name = 'temperature'

    time = attributes.TimestampFieldAttribute()
    phase = attributes.TagFieldAttribute()
    value = attributes.FloatFieldAttribute()

Fields: GenericFieldAttribute (IntegerFieldAttribute, FloatFieldAttribute, StringFieldAttribute, BooleanFieldAttribute), TagFieldAttribute, TimestampFieldAttribute, DateTimeFieldAttribute

Parser Classes: MeasurementPointSerializer (default), JsonSerializer, FormattedSerieSerializer, FlatFormattedSerieSerializer, FlatSimpleResultSerializer, PandasSerializer

Simple Measurement

from influxable.measurement import SimpleMeasurement

my_measurement = SimpleMeasurement('temperature', ['value'], ['phase'])

Query

You can query with Measurement.get_query():

from influxable.db import Field

points = TemperatureMeasurement\
  .get_query()\
  .select('phase', 'value')\
  .where(
     Field('value') > 15.2,
     Field('value') < 30.5,
  )\
  .limit(100)\
  .evaluate()

Saving Data

You can create data by using Measurement.bulk_save()

points = [
    TemperatureMeasurement(phase="HOT", value=10, time=1463289075),
    TemperatureMeasurement(phase="COLD", value=10, time=1463289076),
]
TemperatureMeasurement.bulk_save(points)

Auto Generation of Measurements

You can automatically generate measurement classes file with the bash command autogenerate

influxable autogenerate  # (default to auto_generate_measurement.py)
influxable autogenerate -o measurement.py

Influxable commands

influxable autogenerate
influxable autogenerate -o measurement.py
influxable populate
influxable populate --min_value 5 --max_value 35 -s 2011-01-01T00:00:00 -id 1
influxable populate --help

Testing

First, you need to install pytest via the file requirements-test.txt

pip install -r requirements-test.txt

Then, you can launch the pytest command:

pytest -v

Supporting

Feel free to post issues, your feedback or if you reach a problem with influxable library.

If you want to contribute, please use the pull requests section.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Contributors

Credits

References

License

MIT