InfluxDB access via IPython
Project description
- Author:
Robert Hajek, Bonitoo.io
Introduces a %flux (or %%flux) magic. Connect to a InfluxDB and run Flux commands within IPython or IPython 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 provide a list of existing connections; however, if no connections have yet been made and the environment variable INFLUXDB_V2_URL is available, that will be used.
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 [5]: %flux --persist dataframe
In [6]: %flux from(bucket: "apm_metricset") | filter(fn: (r) => r["_measurement"] == "dataframe" |> range(start: 0)
Options
- -l / --connections
List all active connections
- -t / --token
InfluxDB token
- -o / --org
InfluxDB org
- -x / --close <session-name>
Close named connection
- -p / --persist
Create a measurement in the database from the named DataFrame
- -f / --file <path>
Run Flux from file at this path
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
Development
News
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
Built Distribution
Hashes for ipython_flux-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d08806ca485feb3a20e22a6c0c0523b04d9aa84e8f06a8bc363cb7db05e8b9e2 |
|
MD5 | 3d1e510981c59244f2b6c384b88af799 |
|
BLAKE2b-256 | b6bdbed29d193ab8ee7f4020f07267de36d14ae3f82cd0bd2fb4e97f12ae559d |