Skip to content

Commit 3ab875a

Browse files
author
aviau
committed
Allow top-level tags with write_points
1 parent 7576b33 commit 3ab875a

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

influxdb/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def write_points(self,
243243
time_precision=None,
244244
database=None,
245245
retention_policy=None,
246+
tags=None,
246247
):
247248
"""
248249
Write to multiple time series names.
@@ -258,13 +259,15 @@ def write_points(self,
258259
return self._write_points(points=points,
259260
time_precision=time_precision,
260261
database=database,
261-
retention_policy=retention_policy)
262+
retention_policy=retention_policy,
263+
tags=tags)
262264

263265
def _write_points(self,
264266
points,
265267
time_precision,
266268
database,
267-
retention_policy):
269+
retention_policy,
270+
tags):
268271
if time_precision not in ['n', 'u', 'ms', 's', 'm', 'h', None]:
269272
raise ValueError(
270273
"Invalid time precision is given. "
@@ -285,6 +288,9 @@ def _write_points(self,
285288
if retention_policy:
286289
data['retentionPolicy'] = retention_policy
287290

291+
if tags:
292+
data['tags'] = tags
293+
288294
data['database'] = database or self._database
289295

290296
if self.use_udp:

tests/influxdb/client_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,30 @@ def test_write_points(self):
161161
json.loads(m.last_request.body)
162162
)
163163

164+
def test_write_points_toplevel_attributes(self):
165+
with requests_mock.Mocker() as m:
166+
m.register_uri(
167+
requests_mock.POST,
168+
"http://localhost:8086/write"
169+
)
170+
171+
cli = InfluxDBClient(database='db')
172+
cli.write_points(
173+
self.dummy_points,
174+
database='testdb',
175+
tags={"tag": "hello"},
176+
retention_policy="somepolicy"
177+
)
178+
self.assertDictEqual(
179+
{
180+
"database": "testdb",
181+
"tags": {"tag": "hello"},
182+
"points": self.dummy_points,
183+
"retentionPolicy": "somepolicy"
184+
},
185+
json.loads(m.last_request.body)
186+
)
187+
164188
@unittest.skip('Not implemented for 0.9')
165189
def test_write_points_batch(self):
166190
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')

0 commit comments

Comments
 (0)