File tree 3 files changed +53
-0
lines changed
3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 11
11
12
12
### Documentation
13
13
1 . [ #202 ] ( https://github.com/influxdata/influxdb-client-python/pull/202 ) : Added an example how to use RxPY and sync batching
14
+ 1 . [ #213 ] ( https://github.com/influxdata/influxdb-client-python/pull/213 ) : Added an example how to use Buckets API
14
15
15
16
## 1.15.0 [ 2021-03-05]
16
17
Original file line number Diff line number Diff line change 11
11
- [ query.py] ( query.py ) - How to query data into ` FluxTable ` s, ` Stream ` and ` CSV `
12
12
- [ query_from_file.py] ( query_from_file.py ) - How to use a Flux query defined in a separate file
13
13
14
+
15
+ ## Management API
16
+ - [ buckets_management.py] ( buckets_management.py ) - How to create, list and delete Buckets
17
+
14
18
## Others
15
19
- [ influx_cloud.py] ( influx_cloud.py ) - How to connect to InfluxDB 2 Cloud
16
20
- [ influxdb_18_example.py] ( influxdb_18_example.py ) - How to connect to InfluxDB 1.8
Original file line number Diff line number Diff line change
1
+ """
2
+ How to How to create, list and delete Buckets.
3
+ """
4
+
5
+ from influxdb_client import InfluxDBClient , BucketRetentionRules
6
+
7
+ """
8
+ Define credentials
9
+ """
10
+ url = "http://localhost:8086"
11
+ token = "my-token"
12
+
13
+ client = InfluxDBClient (url = url , token = token )
14
+ buckets_api = client .buckets_api ()
15
+
16
+ """
17
+ The Bucket API uses as a parameter the Organization ID. We have to retrieve ID by Organization API.
18
+ """
19
+ org_name = "my-org"
20
+ org = list (filter (lambda it : it .name == org_name , client .organizations_api ().find_organizations ()))[0 ]
21
+
22
+ """
23
+ Create Bucket with retention policy set to 3600 seconds and name "bucket-by-python"
24
+ """
25
+ print (f"------- Create -------\n " )
26
+ retention_rules = BucketRetentionRules (type = "expire" , every_seconds = 3600 )
27
+ created_bucket = buckets_api .create_bucket (bucket_name = "bucket-by-python" ,
28
+ retention_rules = retention_rules ,
29
+ org_id = org .id )
30
+ print (created_bucket )
31
+
32
+ """
33
+ List all Buckets
34
+ """
35
+ print (f"\n ------- List -------\n " )
36
+ buckets = buckets_api .find_buckets ().buckets
37
+ print ("\n " .join ([f" ---\n ID: { bucket .id } \n Name: { bucket .name } \n Retention: { bucket .retention_rules } "
38
+ for bucket in buckets ]))
39
+ print ("---" )
40
+
41
+ """
42
+ Delete previously created bucket
43
+ """
44
+ print (f"------- Delete -------\n " )
45
+ buckets_api .delete_bucket (created_bucket )
46
+ print (f" successfully deleted bucket: { created_bucket .name } " )
47
+
48
+ client .close ()
You can’t perform that action at this time.
0 commit comments