fix: add imports to query script

pull/4528/head
Sunbrye Ly 2022-10-05 10:42:56 -07:00
parent bb42c7d8a8
commit 61924a5e91
1 changed files with 19 additions and 2 deletions

View File

@ -97,6 +97,7 @@ client = influxdb_client.InfluxDBClient(
org=org
)
# Write script
write_api = client.write_api(write_options=SYNCHRONOUS)
p = influxdb_client.Point("my_measurement").tag("location", "Prague").field("temperature", 25.3)
@ -157,12 +158,28 @@ write_api.write(bucket=bucket, org=org, record=p)
### Complete example query script
```python
import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS
bucket = "<my-bucket>"
org = "<my-org>"
token = "<my-token>"
# Store the URL of your InfluxDB instance
url="http://localhost:8086"
client = influxdb_client.InfluxDBClient(
url=url,
token=token,
org=org
)
# Query script
query_api = client.query_api()
query = from(bucket:"my-bucket")\
query = 'from(bucket:"my-bucket")\
|> range(start: -10m)\
|> filter(fn:(r) => r._measurement == "my_measurement")\
|> filter(fn: (r) => r.location == "Prague")\
|> filter(fn:(r) => r._field == "temperature" )
|> filter(fn:(r) => r._field == "temperature" )'
result = query_api.query(org=org, query=query)
results = []
for table in result: