InfluxDB
Available to teams and users on all plans
Use Deepnote to query time series data in InfluxDB v2 with Python and Flux.
1. Download and import the InfluxDB example
Download the InfluxDB example notebook and follow the Jupyter notebook import steps to add it to your project. After importing it, connect the notebook to your InfluxDB instance.
2. Connect to InfluxDB from Deepnote
To connect to InfluxDB, you need an API token, your organization name, and your InfluxDB instance URL.
Create an InfluxDB token
Create an InfluxDB token with read access to the bucket you want to query.
Update the token in the notebook
Change the variable INFLUXDB_TOKEN to the token you made in the previous step.
Update the organization and URL details in the notebook
Set INFLUXDB_ORG to your organization name.
Change the variable INFLUXDB_URL to the URL where your InfluxDB instance is located.
3. Query InfluxDB from Deepnote
The template creates an InfluxDB Python client. Use client.query_api() to run a Flux query and return a pandas DataFrame. This example queries InfluxDB's air sensor sample data.
import pandas as pd
query_api = client.query_api()
query = """import "influxdata/influxdb/sample"
sample.data(set: "airSensor")
|> filter(fn: (r) => r._field == "temperature")
|> range(start: -45m)
|> aggregateWindow(every: 1m, fn: mean)"""
result = query_api.query_data_frame(query)
if isinstance(result, list):
df = pd.concat(result, ignore_index=True) if result else pd.DataFrame()
else:
df = result
df
The client returns a DataFrame or, when result tables have different schemas, a list of DataFrames. The code combines that list into one DataFrame for display.
What's next?
Share your results with your team or publish your notebook as an app.
For more connection and query options, see the InfluxDB Python client documentation.