Skip to main content

InfluxDB Alchemy.

Project description

InfluxAlchemy

pypi python pytest coverage maintainability

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


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.3.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

influxalchemy-0.3.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file influxalchemy-0.3.0.tar.gz.

File metadata

  • Download URL: influxalchemy-0.3.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for influxalchemy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 59374c2995efdea992e3c4ab7ea1ced2fb85bbbc1b2482bbeeb3cb2def1c13b6
MD5 c1278b12609cc8596e2b4fc8edcceac5
BLAKE2b-256 f8285cf327148c313cb1f158300c953bc03558a2a284f8b78fc7a78d6ae94896

See more details on using hashes here.

File details

Details for the file influxalchemy-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for influxalchemy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb5c1532b4525c24f6db1ace63de380bcc19a9347bc25e5341e9277aea68d40c
MD5 0fe43a262b6ecb8705a098935ea4d409
BLAKE2b-256 bab92ff0f117a123290daa09358f39d375dee1b126658db340fa7a1ab49e0c36

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page