3

I'm having trouble understanding how to use some InfluxDB 2 APIs from Python, using the influxdb-client-python library for InfluxDB 2

For example I would like to get a list of measurements in a bucket.

Official documentation (not Python) suggest this:

Use the schema.measurements() function to list measurements in a bucket.

import "influxdata/influxdb/schema"
schema.measurements(bucket: "example-bucket")
mattewre
  • 91
  • 2
  • 6

1 Answers1

1

I have searched through the library's code to see if I could find something that does this. I might be wrong, but it appears that as of right now there's no interface for this functionality.

However, it is possible to do what you want by executing the following:

from influxdb_client import InfluxDBClient

address = "myaddress"
token = "mytoken"
org = "myorg"

client = InfluxDBClient(url=address, token=token, org=org)
qapi = client.query_api()

q = 'import "influxdata/influxdb/schema"\n\nschema.measurements(bucket: "example-bucket")'

tables = qapi.query(q)
for table in tables:
     print(table)
     for record in table.records:
         print(record.values)

You will have to substitute any defined variables from this code sample with your own. Also, make sure that the bucket name in the query matches the bucket you want to query.

Finally, the token you use must have enough permissions to accomplish the task.

Kevin King
  • 11
  • 2
  • for more info see: https://docs.influxdata.com/influxdb/v2.0/query-data/flux/explore-schema/#list-measurements – AmanicA Dec 23 '22 at 02:03