InfluxDB Alchemy.
Project description
InfluxAlchemy
Query InfluxDB using SQLAlchemy-style syntax
Installation
pip install influxalchemy
Usage
import influxdb
import influxalchemy
Define InfluxAlchemy Measurements
class Widgets(influxalchemy.Measurement):
__measurement__ = 'widgets'
class Wombats(influxalchemy.Measurement):
__measurement__ = 'wombats'
The class-attribute __measurement__
can be omitted and will default to the class name if absent.
Open InfluxAlchemy Connection
db = influxdb.DataFrameClient(database="example")
flux = influxalchemy.InfluxAlchemy(db)
Query InfluxDB
Query Single Measurement
# SELECT * FROM widgets;
flux.query(Widgets)
Query Ad Hoc Measurement
# SELECT * from /.*/;
flux.query(influxalchemy.Measurement.new("/.*/"))
Select Fields of Measurement
# SELECT tag1, field2 FROM widgets;
flux.query(Widgets.tag1, Widgets.field2)
Query Across Measurements
# SELECT * FROM /widgets|wombats/;
flux.query(Widgets | Wombats)
Filter Tags
# SELECT * FROM widgets WHERE tag1 = 'fizz';
flux.query(Widgets).filter(Widgets.tag1 == "fizz")
Filter Tags with 'like'
# SELECT * FROM widgets WHERE tag1 =~ /z$/;
flux.query(Widgets).filter(Widgets.tag1.like("/z$/"))
Chain Filters
clause1 = Widgets.tag1 == "fizz"
clause2 = Widgets.tag2 == "buzz"
# SELECT * FROM widgets WHERE tag1 = 'fizz' AND tag2 = 'buzz';
flux.query(Widgets).filter(clause1 & clause2)
# SELECT * FROM widgets WHERE tag1 = 'fizz' OR tag2 = 'buzz';
flux.query(Widgets).filter(clause1 | clause2)
Group By
# SELECT * FROM widgets GROUP BY time(1d);
flux.query(Widgets).group_by("time(1d)")
# SELECT * FROM widgets GROUP BY tag1;
flux.query(Widgets).group_by(Widgets.tag1)
Time
# SELECT * FROM widgets WHERE (time > now() - 7d);
flux.query(Widgets).filter(Widgets.time > "now() - 7d")
# SELECT * FROM widgets WHERE time >= '2016-01-01' AND time <= now() - 7d;
d = date(2016, 1, 1)
flux.query(Widgets).filter(Widgets.time.between(d, "now() - 7d"))
Note that naive datetime object will be assumed in UTC timezone.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
influxalchemy-0.2.7.tar.gz
(11.4 kB
view hashes)
Built Distribution
Close
Hashes for influxalchemy-0.2.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52ae9fe29124de69b2b01390f0729812356fc9f6d21d68196aac9e7c654195c1 |
|
MD5 | 4ba8a7136e8634b4957ccbc8a404ff4b |
|
BLAKE2b-256 | 4e051c1169409976739638720d81539fde53353f81602afc06b33328e9ad8c2f |