Skip to main content

InfluxDB access via IPython

Project description

https://circleci.com/gh/bonitoo-io/ipython-flux.svg?style=svg
Author:

Robert Hajek, Bonitoo.io

Introduces a %flux (or %%flux) magic.

Connect to a InfluxDB and run Flux commands within IPython or IPython Notebook.

screenshot of ipython-flux in the Notebook

Examples

In [1]: %load_ext flux

In [2]: %%flux http://localhost:9999 --token my-token --org my-org
   ...: from(bucket: "apm_metricset")
   ...:   |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
   ...:   |> filter(fn: (r) => r["_measurement"] == "apm_metricset")
   ...:   |> filter(fn: (r) => r["_field"] == "samples_system.process.cpu.total.norm.pct")
   ...:
Out[2]: ...

After the first connection, connect info can be omitted:

In [3]: %flux
   ...: from(bucket: "apm_metricset")
   ...:   |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
   ...:   |> filter(fn: (r) => r["_measurement"] == "apm_metricset")
   ...:   |> filter(fn: (r) => r["_field"] == "samples_system.process.cpu.total.norm.pct")

Out[8]: ...

If no connect string is supplied, %flux will use environment variables INFLUXDB_V2_URL, INFLUXDB_V2_ORG, INFLUXDB_V2_TOKEN to create connection into InfluxDB.

Assignment

Ordinary IPython assignment works for single-line %flux queries:

In [12]: result = %flux from(bucket: "apm_metricset")  |> range(start: 0)

The << operator captures query results in a local variable, and can be used in multi-line %%flux:

In [19]: %%flux works << %flux from(bucket: "apm_metricset")
    ...: |> range(start: 0)
    ...:

Pandas

result is automatically converted into pandas dataframe

In [3]: result =  %flux from(bucket: "apm_metricset")  |> range(start: 0)

The --persist argument, with the name of a DataFrame object in memory will create a measurement in the database from the named DataFrame.

In [1]: %flux --persist <data_frame_variable_name> --bucket my-bucket --measurement <new measurement name> --tags tag_column1,tag_column2

Options

-l / --connections

List all active connections

-t / --token

InfluxDB token

-o / --org

InfluxDB org

-f / --file <path>

Run Flux from file at this path

-x / --close <session-name>

Close named connection

Persist options

-p / --persist

Create a measurement in the database from the named DataFrame

-b / --bucket

target bucket name

-T / --tags

comma separated list of columns that will be stored as tags, rest of columns will be stored as fields

-m / --measurement

optional, target measurement name, if not specified measurement is taken from dataframe name

Installing

Install the lastest release with:

pip install ipython-flux

or download from https://github.com/bonitoo-io/ipython-flux and:

cd ipython-flux
sudo python setup.py install

Enable IPython flux magic extension in Jupyter notebook using

In [1]: %load_ext flux

Development

https://github.com/bonitoo-io/ipython-flux

News

0.0.2

Release date: 6-08-2020

  • Fixed connection creation from os enviroment variables

  • Added persist dataframe into InfluxDB

0.0.1

Release date: 21-07-2020

  • Initial release

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

ipython-flux-0.0.2.tar.gz (9.0 kB view details)

Uploaded Source

File details

Details for the file ipython-flux-0.0.2.tar.gz.

File metadata

  • Download URL: ipython-flux-0.0.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.4

File hashes

Hashes for ipython-flux-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c27da5d75e8b8c0dfebbc4673cf7f0a74913b0da1498eecb1bcac0d7f41a59be
MD5 73893d6e40f34dc082ae139e3bae4dc7
BLAKE2b-256 47bcea2acf7fae81af5614c8baaea446bd2049c0807ff354ccddae4177acc6a8

See more details on using hashes here.

Supported by

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