|
1 |
| -""" |
2 |
| -How to How to create, list and delete Buckets. |
3 |
| -""" |
| 1 | +from influxdb_client import InfluxDBClient |
| 2 | +from influxdb_client.client.write_api import SYNCHRONOUS |
4 | 3 |
|
5 |
| -from influxdb_client import InfluxDBClient, BucketRetentionRules |
6 |
| - |
7 |
| -""" |
8 |
| -Define credentials |
9 |
| -""" |
10 |
| -url = "http://localhost:8086" |
11 |
| -token = "my-token" |
12 |
| -org = "my-org" |
13 |
| - |
14 |
| -with InfluxDBClient(url=url, token=token) as client: |
15 |
| - buckets_api = client.buckets_api() |
16 |
| - |
17 |
| - """ |
18 |
| - Create Bucket with retention policy set to 3600 seconds and name "bucket-by-python" |
19 |
| - """ |
20 |
| - print(f"------- Create -------\n") |
21 |
| - retention_rules = BucketRetentionRules(type="expire", every_seconds=3600) |
22 |
| - created_bucket = buckets_api.create_bucket(bucket_name="bucket-by-python", |
23 |
| - retention_rules=retention_rules, |
24 |
| - org=org) |
25 |
| - print(created_bucket) |
26 |
| - |
27 |
| - """ |
28 |
| - List all Buckets |
29 |
| - """ |
30 |
| - print(f"\n------- List -------\n") |
31 |
| - buckets = buckets_api.find_buckets().buckets |
32 |
| - print("\n".join([f" ---\n ID: {bucket.id}\n Name: {bucket.name}\n Retention: {bucket.retention_rules}" |
33 |
| - for bucket in buckets])) |
34 |
| - print("---") |
35 |
| - |
36 |
| - """ |
37 |
| - Delete previously created bucket |
38 |
| - """ |
39 |
| - print(f"------- Delete -------\n") |
40 |
| - buckets_api.delete_bucket(created_bucket) |
41 |
| - print(f" successfully deleted bucket: {created_bucket.name}") |
| 4 | +with InfluxDBClient(url='http://localhost:8086', token='my-token', org='my-org') as client: |
| 5 | + write_api = client.write_api(write_options=SYNCHRONOUS) |
42 | 6 |
|
| 7 | + write_api.write(bucket='my-bucket', record='h2o_feet,location=coyote_creek water_level=1.0 1') |
0 commit comments