Introduction
Influxable is a lightweight Python ORM / ODM / Client for InfluxDB .
This repository allows users to deal with InfluxDB in a smooth way and to manipulate Python object.
Link
Link : https://github.com/Javidjms/influxable
Link Release : https://github.com/Javidjms/influxable/releases/tag/1.3.0
Getting Started
The package is available in pypi. You can install it via pip :
pip install influxable
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
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',
)
Create a Measurement Class
There is a built-in Measurement mapper class that you can extend it :
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()
You can also create a measurement mapper class quickly with the SimpleMeasurement class :
from influxable.measurement import SimpleMeasurement
TemperatureMeasurement = SimpleMeasurement('temperature', ['value'], ['phase'])
Create Queries
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()
You can also query with Query :
from influxable.db import Query, Field
points = Query()\
.select('phase', 'value')\
.from_measurements('temperature')\
.where(
Field('value') > 15.2,
Field('value') < 30.5,
)\
.limit(100)
.execute()
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)
You can also create data with BulkInsertQuery
str_query = '''
temperature,phase=HOT value=10 1463289075000000000
temperature,phase=COLD value=10 1463289076000000000
'''
raw_query = BulkInsertQuery(str_query)
res = raw_query.execute()
Other Features
group_by()
range_by
populate command
autogenerate measurements command
multiple serializer like PandasSerializer
etc
Top comments (0)