Use InfluxDB client libraries and SQL or InfluxQL to query data
Use the InfluxDB v3 client libraries with SQL or InfluxQL to query data stored in InfluxDB. InfluxDB v3 client libraries are language-specific packages that integrate with your application. Execute queries and retrieve data and metadata over the Flight+gRPC protocol, and then process data using tools in the language of your choice.
Use Go
Use the influxdb3-go
Go package and SQL or InfluxQL to query data stored in InfluxDB. Execute queries and retrieve data over the Flight+gRPC protocol, and then process data using common Go tools.
import (
"context"
"github.com/InfluxCommunity/influxdb3-go/influxdb3/v1"
)
func Query() error {
client, err := influxdb3.New(influxdb3.ClientConfig{
Host: "https://cluster-host.com",
Token: "DATABASE_TOKEN",
Database: "DATABASE_NAME",
})
defer func(client *influxdb3.Client) {
err := client.Close()
if err != nil {
panic(err)
}
}(client)
query := `SELECT *
FROM home
WHERE time >= '2022-01-02T08:00:00Z'
AND time <= '2022-01-02T20:00:00Z'`
iterator, err := client.Query(context.Background(), query)
...
}
Use Python
Use the influxdb_client_3
Python module and SQL or InfluxQL to query data stored in InfluxDB. Execute queries and retrieve data over the Flight+gRPC protocol, and then process data using common Python tools.
from influxdb_client_3 import InfluxDBClient3
# Instantiate an InfluxDB client
client = InfluxDBClient3(
host='cluster-host.com',
token='DATABASE_TOKEN',
database='DATABASE_NAME'
)
# Execute the query and return an Arrow table
table = client.query(
query="SELECT * FROM home",
language="sql"
)
# Return query results as a markdown table
print(table.to_pandas().to_markdown())
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, use the following resources:
Customers with an annual or support contract can contact InfluxData Support.