Skip to content

Commit 914dd59

Browse files
committed
docs: how to write LineProtocol
1 parent 7091683 commit 914dd59

File tree

2 files changed

+17
-40
lines changed

2 files changed

+17
-40
lines changed

MIGRATION_GUIDE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,23 @@ with InfluxDBClient(url='http://localhost:8086', token='my-token', org='my-org')
9999
**influxdb-python**
100100

101101
```python
102+
from influxdb import InfluxDBClient
103+
104+
client = InfluxDBClient(host='127.0.0.1', port=8086, username='root', password='root', database='dbname')
105+
106+
client.write('h2o_feet,location=coyote_creek water_level=1.0 1', protocol='line')
102107
```
103108

104109
**influxdb-client-python**
105110

106111
```python
112+
from influxdb_client import InfluxDBClient
113+
from influxdb_client.client.write_api import SYNCHRONOUS
114+
115+
with InfluxDBClient(url='http://localhost:8086', token='my-token', org='my-org') as client:
116+
write_api = client.write_api(write_options=SYNCHRONOUS)
117+
118+
write_api.write(bucket='my-bucket', record='h2o_feet,location=coyote_creek water_level=1.0 1')
107119
```
108120

109121
## Writing Point Object

examples/buckets_management.py

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,7 @@
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
43

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)
426

7+
write_api.write(bucket='my-bucket', record='h2o_feet,location=coyote_creek water_level=1.0 1')

0 commit comments

Comments
 (0)