8000 added write ability and examples · InfluxCommunity/influxdb3-python@2610d10 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2610d10

Browse files
author
Jay Clifford
committed
added write ability and examples
1 parent 38d2de4 commit 2610d10

File tree

13 files changed

+473
-28
lines changed

13 files changed

+473
-28
lines changed

Examples/csv_write.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

Examples/file-import/csv_write.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import influxdb_client_3 as InfluxDBClient3
2 8000 +
import pandas as pd
3+
import numpy as np
4+
from influxdb_client_3 import write_client_options, WritePrecision, WriteOptions, InfluxDBError
5+
6+
7+
class BatchingCallback(object):
8+
9+
def success(self, conf, data: str):
10+
print(f"Written batch: {conf}, data: {data}")
11+
12+
def error(self, conf, data: str, exception: InfluxDBError):
13+
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")
14+
15+
def retry(self, conf, data: str, exception: InfluxDBError):
16+
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")
17+
18+
callback = BatchingCallback()
19+
20+
write_options = WriteOptions(batch_size=500,
21+
flush_interval=10_000,
22+
jitter_interval=2_000,
23+
retry_interval=5_000,
24+
max_retries=5,
25+
max_retry_delay=30_000,
26+
exponential_base=2)
27+
28+
wco = write_client_options(success_callback=callback.success,
29+
error_callback=callback.error,
30+
retry_callback=callback.retry,
31+
WriteOptions=write_options
32+
)
33+
34+
with InfluxDBClient3.InfluxDBClient3(
35+
token="INSERT_TOKEN",
36+
host="eu-central-1-1.aws.cloud2.influxdata.com",
37+
org="6a841c0c08328fb1",
38+
database="python", _write_client_options=wco) as client:
39+
40+
41+
client.write_file(
42+
file='./out.csv',
43+
timestamp_column='time', tag_columns=["provider", "machineID"])

Examples/file-import/feather_write.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import influxdb_client_3 as InfluxDBClient3
2+
import pandas as pd
3+
import numpy as np
4+
from influxdb_client_3 import write_client_options, WritePrecision, WriteOptions, InfluxDBError
5+
6+
7+
class BatchingCallback(object):
8+
9+
def success(self, conf, data: str):
10+
print(f"Written batch: {conf}, data: {data}")
11+
12+
def error(self, conf, data: str, exception: InfluxDBError):
13+
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")
14+
15+
def retry(self, conf, data: str, exception: InfluxDBError):
16+
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")
17+
18+
callback = BatchingCallback()
19+
20+
write_options = WriteOptions(batch_size=500,
21+
flush_interval=10_000,
22+
jitter_interval=2_000,
23+
retry_interval=5_000,
24+
max_retries=5,
25+
max_retry_delay=30_000,
26+
exponential_base=2)
27+
28+
wco = write_client_options(success_callback=callback.success,
29+
error_callback=callback.error,
30+
retry_callback=callback.retry,
31+
WriteOptions=write_options
32+
)
33+
34+
with InfluxDBClient3.InfluxDBClient3(
35+
token="INSERT_TOKEN",
36+
host="eu-central-1-1.aws.cloud2.influxdata.com",
37+
org="6a841c0c08328fb1",
38+
database="python", _write_client_options=wco) as client:
39+
40+
41+
client.write_file(
42+
file='./out.feather',
43+
timestamp_column='time', tag_columns=["provider", "machineID"])

Examples/file-import/json_write.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import influxdb_client_3 as InfluxDBClient3
2+
import pandas as pd
3+
import numpy as np
4+
from influxdb_client_3 import write_client_options, WritePrecision, WriteOptions, InfluxDBError
5+
6+
7+
class BatchingCallback(object):
8+
9+
def success(self, conf, data: str):
10+
print(f"Written batch: {conf}, data: {data}")
11+
12+
def error(self, conf, data: str, exception: InfluxDBError):
13+
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")
14+
15+
def retry(self, conf, data: str, exception: InfluxDBError):
16+
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")
17+
18+
callback = BatchingCallback()
19+
20+
write_options = WriteOptions(batch_size=500,
21+
flush_interval=10_000,
22+
jitter_interval=2_000,
23+
retry_interval=5_000,
24+
max_retries=5,
25+
max_retry_delay=30_000,
26+
exponential_base=2)
27+
28+
wco = write_client_options(success_callback=callback.success,
29+
error_callback=callback.error,
30+
retry_callback=callback.retry,
31+
WriteOptions=write_options
32+
)
33+
34+
with InfluxDBClient3.InfluxDBClient3(
35+
token="INSERT_TOKEN",
36+
host="eu-central-1-1.aws.cloud2.influxdata.com",
37+
org="6a841c0c08328fb1",
38+
database="python", _write_client_options=wco) as client:
39+
40+
41+
42+
43+
client.write_file(
44+
file='./out.json',
45+
timestamp_column='time', tag_columns=["provider", "machineID"], date_unit='ns' )
46+

Examples/file-import/orc_write.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import influxdb_client_3 as InfluxDBClient3
2+
import pandas as pd
3+
import numpy as np
4+
from influxdb_client_3 import write_client_options, WritePrecision, WriteOptions, InfluxDBError
5+
6+
7+
class BatchingCallback(object):
8+
9+
def success(self, conf, data: str):
10+
print(f"Written batch: {conf}, data: {data}")
11+
12+
def error(self, conf, data: str, exception: InfluxDBError):
13+
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")
14+
15+
def retry(self, conf, data: str, exception: InfluxDBError):
16+
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")
17+
18+
callback = BatchingCallback()
19+
20+
write_options = WriteOptions(batch_size=500,
21+
flush_interval=10_000,
22+
jitter_interval=2_000,
23+
retry_interval=5_000,
24+
max_retries=5,
25+
max_retry_delay=30_000,
26+
exponential_base=2)
27+
28+
wco = write_client_options(success_callback=callback.success,
29+
error_callback=callback.error,
30+
retry_callback=callback.retry,
31+
WriteOptions=write_options
32+
)
33+
34+
with InfluxDBClient3.InfluxDBClient3(
35+
token="INSERT_TOKEN",
36+
host="eu-central-1-1.aws.cloud2.influxdata.com",
37+
org="6a841c0c08328fb1",
38+
database="python", _write_client_options=wco) as client:
39+
40+
41+
42+
43+
client.write_file(
44+
file='./out.orc',
45+
timestamp_column='time', tag_columns=["provider", "machineID"])
46+

0 commit comments

Comments
 (0)
0