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.
Metadata
Release files for influxalchemy 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| influxalchemy-0.3.0.tar.gz | 11.5 kB | Without provenance | Details for influxalchemy-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| influxalchemy-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for influxalchemy-0.3.0-py3-none-any.whl |
Total release size: 19.0 kB
Release files / influxalchemy-0.3.0.tar.gz
| Download URL | influxalchemy-0.3.0.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
59374c2995efdea992e3c4ab7ea1ced2fb85bbbc1b2482bbeeb3cb2def1c13b6
|
|
BLAKE2b-256 checksum How to use checksums |
f8285cf327148c313cb1f158300c953bc03558a2a284f8b78fc7a78d6ae94896
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Release files / influxalchemy-0.3.0-py3-none-any.whl
| Download URL | influxalchemy-0.3.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb5c1532b4525c24f6db1ace63de380bcc19a9347bc25e5341e9277aea68d40c
|
|
BLAKE2b-256 checksum How to use checksums |
bab92ff0f117a123290daa09358f39d375dee1b126658db340fa7a1ab49e0c36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Security for influxalchemy 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.