Query InfluxDB using SQLAlchemy-style syntax
bash
pip install influxalchemy
python
import influxdb
import influxalchemy
```python 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.
python
db = influxdb.DataFrameClient(database="example")
flux = influxalchemy.InfluxAlchemy(db)
```python
flux.query(Widgets) ```
```python
flux.query(influxalchemy.Measurement.new("/.*/")) ```
```python
flux.query(Widgets.tag1, Widgets.field2) ```
```python
flux.query(Widgets | Wombats) ```
```python
flux.query(Widgets).filter(Widgets.tag1 == "fizz") ```
```python
flux.query(Widgets).filter(Widgets.tag1.like("/z$/")) ```
```python clause1 = Widgets.tag1 == "fizz" clause2 = Widgets.tag2 == "buzz"
flux.query(Widgets).filter(clause1 & clause2)
flux.query(Widgets).filter(clause1 | clause2) ```
```python
flux.query(Widgets).group_by("time(1d)")
flux.query(Widgets).group_by(Widgets.tag1) ```
```python
flux.query(Widgets).filter(Widgets.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.
How add aggregator functions like mean, sum, integral...?
Like this: flux.query(ElectricalMeasurement.power.integral.as.energy).filter(clause1 & clause2).group_by(group_by)
migrate to pyproject.toml drop support for Python 3.6 and earlier
Python 3.9 support
Security updates
docker-compose.yml
for playing with test data.LIMIT
functionality (https://github.com/amancevice/influxalchemy/pull/4)six
dependency to help with Python 2/3 compatibility re Metaclass'inginfluxdb sqlalchemy python