Skip to content

Commit b47e697

Browse files
committed
docs: how to write Dictionary-style object
1 parent ae71b29 commit b47e697

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

MIGRATION_GUIDE.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Please take a moment to review the following client docs:
1818
- [Initializing Client](#initializing-client)
1919
- [Creating Database/Bucket](#creating-databasebucket)
2020
- [Dropping Database/Bucket](#dropping-databasebucket)
21+
- [Writing LineProtocol](#writing-lineprotocol)
22+
- [Writing Dictionary-style object](#writing-dictionary-style-object)
2123

2224
## Initializing Client
2325

@@ -118,16 +120,63 @@ with InfluxDBClient(url='http://localhost:8086', token='my-token', org='my-org')
118120
write_api.write(bucket='my-bucket', record='h2o_feet,location=coyote_creek water_level=1.0 1')
119121
```
120122

121-
## Writing Point Object
123+
## Writing Dictionary-style object
122124

123125
**influxdb-python**
124126

125127
```python
128+
from influxdb import InfluxDBClient
129+
130+
record = [
131+
{
132+
"measurement": "cpu_load_short",
133+
"tags": {
134+
"host": "server01",
135+
"region": "us-west"
136+
},
137+
"time": "2009-11-10T23:00:00Z",
138+
"fields": {
139+
"Float_value": 0.64,
140+
"Int_value": 3,
141+
"String_value": "Text",
142+
"Bool_value": True
143+
}
144+
}
145+
]
146+
147+
client = InfluxDBClient(host='127.0.0.1', port=8086, username='root', password='root', database='dbname')
148+
149+
client.write_points(record)
126150
```
127151

128152
**influxdb-client-python**
129153

130154
```python
155+
from influxdb_client import InfluxDBClient
156+
from influxdb_client.client.write_api import SYNCHRONOUS
157+
158+
with InfluxDBClient(url='http://localhost:8086', token='my-token', org='my-org') as client:
159+
write_api = client.write_api(write_options=SYNCHRONOUS)
160+
161+
record = [
162+
{
163+
"measurement": "cpu_load_short",
164+
"tags": {
165+
"host": "server01",
166+
"region": "us-west"
167+
},
168+
"time": "2009-11-10T23:00:00Z",
169+
"fields": {
170+
"Float_value": 0.64,
171+
"Int_value": 3,
172+
"String_value": "Text",
173+
"Bool_value": True
174+
}
175+
}
176+
]
177+
178+
write_api.write(bucket='my-bucket', record=record)
179+
131180
```
132181

133182
## Writing Structured Data

0 commit comments

Comments
 (0)