influxdb_client_3
is a Python module that provides a simple and convenient way to interact with InfluxDB 3.0. This module supports both writing data to InfluxDB and querying data using the Flight client, which allows you to execute SQL and InfluxQL queries on InfluxDB 3.0.
pyarrow
influxdb-client
You can install the dependencies using pip
:
pip install influxdb3-client
from influxdb_client_3 import InfluxDBClient3, Point
If you are using InfluxDB Cloud, then you should note that:
- You will need to supply your org id, this is not necessary for InfluxDB Dedicated.
- Use a bucketname for the database argument.
client = InfluxDBClient3(token="your-token",
host="your-host",
org="your-org",
database="your-database")
You can write data using the Point class, or supplying line protocol.
point = Point("measurement").tag("location", "london").field("temperature", 42)
client.write(point)
point = "measurement fieldname=0"
client.write(point)
query = "select * from measurement"
reader = client.query(query=query, language="sql")
table = reader.read_all()
print(table.to_pandas().to_markdown())
query = "select * from measurement"
reader = client.query(query=query, language="influxql")
table = reader.read_all()
print(table.to_pandas().to_markdown())