Package: ipython-flux
Author:Robert Hajek, Bonitoo.ioIntroduces a %flux (or %%flux) magic.Connect to a InfluxDB and run Flux commands within IPython or IPython Notebook.ExamplesIn[1]:%load_extfluxIn[2]:%%fluxhttp://localhost:9999--token"my-token"--orgmy-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,%fluxwill use environment variablesINFLUXDB_V2_URL,INFLUXDB_V2_ORG,INFLUXDB_V2_TOKENto create connection into InfluxDB.Ordinary IPython assignment works for single-line%fluxqueries:In[12]:result=%fluxfrom(bucket:"my-bucket")|>range(start:0)The<<operator captures query results in a local variable, and
can be used in multi-line%%flux:In[19]:%%fluxmy_dataset<<...:from(bucket:"my-bucket")...:|>range(start:-30m)...:|>filter(fn:(r)=>r["_measurement"]=="cpu")...:|>filter(fn:(r)=>r["_field"]=="usage_idle"orr["_field"]=="usage_system"orr["_field"]=="usage_user")...:|>filter(fn:(r)=>r["cpu"]=="cpu-total")...:|>drop(columns:["_start","_stop","_result","_measurement","table","_result"])...:|>pivot(rowKey:["_time"],columnKey:["_field"],valueColumn:"_value")The result of the Flux command is automatically converted into Pandas dataframe. It is often useful to use Flux
functionsfieldsAsCol()orpivot()to convert data containing multiple timeseries into one dataset.Persist dataframeThe--persistargument, 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>--bucketmy-bucket--measurement<newmeasurementname>--tagstag_column1,tag_column2Options-l/--connectionsList all active connections-t/--tokenInfluxDB token-o/--orgInfluxDB org--timeoutInfluxDB query timeout in milliseconds (default timeout is 10_000 ms)-f/--file<path>Run Flux from file at this path-x/--close<session-name>Close named connectionPersist options-p/--persistCreate a measurement in the database from the named DataFrame-b/--buckettarget bucket name-T/--tagscomma separated list of columns that will be stored as tags, rest of columns will be stored as fields-m/--measurementoptional, target measurement name, if not specified measurement is taken from dataframe nameInstallingInstall the lastest release with:pip install ipython-fluxor download fromhttps://github.com/bonitoo-io/ipython-fluxand:cd ipython-flux
sudo python setup.py installEnable IPython flux magic extension in Jupyter notebook usingIn[1]:%load_extfluxDevelopmenthttps://github.com/bonitoo-io/ipython-fluxNews0.0.6Release date: 06-11-2022#5- Fixsetup.pyformatting0.0.5Release date: 25-03-2022#2- Add connection timeout#3- Change default InfluxDB port from 9999 to 8086, update dependencies0.0.4Release date: 18-08-2020#1: Fixed token argument starts with “-”0.0.3Release date: 12-08-2020Updated tox.ini and requirement dependencies0.0.2Release date: 6-08-2020Fixed connection creation from os enviroment variablesAdded persist dataframe into InfluxDB0.0.1Release date: 21-07-2020Initial release