-
Notifications
You must be signed in to change notification settings - Fork 185
It's unclear from the doc how to manage the buckets #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@andkuzmich, thanks for using our client, We will take a look. |
There is a doc for
This is not simple use case because it suppose that you have a permission to create a bucket. You could use something like this to create bucket if not exists: from influxdb_client import InfluxDBClient, Point, BucketRetentionRules
from influxdb_client.client.write_api import SYNCHRONOUS
from influxdb_client.rest import ApiException
org_id = "36e4880c1d86284a"
bucket = "my-bucket_to_create"
token = "my-token"
client = InfluxDBClient(url="http://localhost:8086", token=token, org=org_id)
write_api = client.write_api(write_options=SYNCHRONOUS)
query_api = client.query_api()
def create_bucket_if_need():
try:
write_api.write(bucket, org_id, b'')
except ApiException as e:
if e.status == 404:
buckets_api = client.buckets_api()
retention_rules = BucketRetentionRules(type='expire', every_seconds=3600)
created_bucket = buckets_api.create_bucket(bucket_name=bucket,
retention_rules=retention_rules,
org_id=org_id)
print(f"created bucket: {created_bucket}")
pass
create_bucket_if_need()
"""
Write Data
"""
point = Point("mem").tag("host", "host1").field("used_percent", 25.43234543)
write_api.write(bucket=bucket, record=point)
"""
Query Data
"""
tables = query_api.query(f'from(bucket: "{bucket}") |> range(start: 0)')
print('\n'.join([f"{record.values}" for records in tables for record in records]))
client.close() |
@bednar, Thank you a lot! I've figured it out from the code, but anyway your example might be helpful for others |
It would be nice if you will provide a fancy example for buckets management API. It's not well documented and requires to go into code if you want to figure out how to create/list/delete the buckets. A simple use case is 'CREATE IF NOT EXISTS' on fly while producer submitting a datahttps://guides.github.com/features/mastering-markdown/
The text was updated successfully, but these errors were encountered: