Skip to content

Commit 06e179c

Browse files
Merge pull request #32 from InfluxCommunity/blog-examples
added synchronous example
2 parents 3dd8cc9 + 1b51173 commit 06e179c

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
from influxdb_client_3 import InfluxDBClient3, Point, SYNCHRONOUS, write_client_options
2+
import pandas as pd
3+
import numpy as np
4+
import datetime
5+
6+
7+
8+
wco = write_client_options(write_options=SYNCHRONOUS)
9+
10+
11+
with InfluxDBClient3(
12+
token="",
13+
host="eu-central-1-1.aws.cloud2.influxdata.com",
14+
org="6a841c0c08328fb1",
15+
database="pokemon-codex", write_client_options=wco, debug=True) as client:
16+
17+
now = datetime.datetime.now(datetime.timezone.utc)
18+
19+
data = Point("caught").tag("trainer", "ash").tag("id", "0006").tag("num", "1")\
20+
.field("caught", "charizard")\
21+
.field("level", 10).field("attack", 30)\
22+
.field("defense", 40).field("hp", 200)\
23+
.field("speed", 10)\
24+
.field("type1", "fire").field("type2", "flying")\
25+
.time(now)
26+
27+
28+
29+
try:
30+
client.write(data)
31+
except Exception as e:
32+
print(f"Error writing point: {e}")
33+
34+
data = []
35+
# Adding first point
36+
data.append(
37+
Point("caught")
38+
.tag("trainer", "ash")
39+
.tag("id", "0006")
40+
.tag("num", "1")
41+
.field("caught", "charizard")
42+
.field("level", 10)
43+
.field("attack", 30)
44+
.field("defense", 40)
45+
.field("hp", 200)
46+
.field("speed", 10)
47+
.field("type1", "fire")
48+
.field("type2", "flying")
49+
.time(now)
50+
)
51+
52+
# Adding second point
53+
data.append(
54+
Point("caught")
55+
.tag("trainer", "ash")
56+
.tag("id", "0007")
57+
.tag("num", "2")
58+
.field("caught", "bulbasaur")
59+
.field("level", 12)
60+
.field("attack", 31)
61+
.field("defense", 31)
62+
.field("hp", 190)
63+
.field("speed", 11)
64+
.field("type1", "grass")
65+
.field("type2", "poison")
66+
.time(now)
67+
)
68+
69+
# Adding third point
70+
data.append(
71+
Point("caught")
72+
.tag("trainer", "ash")
73+
.tag("id", "0008")
74+
.tag("num", "3")
75+
.field("caught", "squirtle")
76+
.field("level", 13)
77+
.field("attack", 29)
78+
.field("defense", 40)
79+
.field("hp", 180)
80+
.field("speed", 13)
81+
.field("type1", "water")
82+
.field("type2", None)
83+
.time(now)
84+
)
85+
86+
87+
try:
88+
client.write(data)
89+
except Exception as e:
90+
print(f"Error writing point: {e}")
91+
92+

influxdb_client_3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
"""
4646
self._org = org
4747
self._database = database
48-
self._write_client_options = write_client_options or {'write_options': SYNCHRONOUS}
48+
self._write_client_options = write_client_options or write_client_options(write_options=SYNCHRONOUS)
4949

5050
# Extracting the hostname from URL if provided
5151
parsed_url = urllib.parse.urlparse(host)

0 commit comments

Comments
 (0)