Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can write measurements in a few different ways, but writing a single
.. code:: python

from inflow import Client
client = Client('http://username:pass@localhost:8086/databasename')
client = Client('http://username:pass@localhost:8086', db='databasename')
client.write('temperature', value=21.3)

For more examples and docs on how to use the client, refer to the Measurements
Expand Down
8 changes: 4 additions & 4 deletions docs/source/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can write measurements in a few different ways, but writing a single
.. code:: python

from inflow import Client
client = Client('http://username:pass@localhost:8086/databasename')
client = Client('http://username:pass@localhost:8086', db='databasename')
client.write('temperature', value=21.3)

No time is specified in the above example, so inflow automatically set's the
Expand All @@ -25,7 +25,7 @@ A more complex example of writing a single measurement:

from inflow import Client

client = Client('http://username:pass@localhost:8086/databasename')
client = Client('http://username:pass@localhost:8086', db='databasename')

client.write(
'temperature'
Expand All @@ -43,7 +43,7 @@ Writing multiple measurements is also possible:

from inflow import Client, Measurement

client = Client('http://username:pass@localhost:8086/databasename')
client = Client('http://username:pass@localhost:8086', db='databasename')

client.write([
Measurement(
Expand Down Expand Up @@ -72,7 +72,7 @@ However, this is a bit verbose. That's why you can also do this:

from inflow import Client, Measurement

client = Client('http://username:pass@localhost:8086/databasename')
client = Client('http://username:pass@localhost:8086', db='databasename')

temperature = Measurement(
name='temperature',
Expand Down
8 changes: 5 additions & 3 deletions examples/different_precision.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python

from inflow import Client
client = Client('http://username:pass@localhost:8086/databasename',
precision='ms')
client.write('temperature', value=21.3, timestamp=1476191999000)

client = Client(
"http://username:pass@localhost:8086", db="databasename", precision="ms"
)
client.write("temperature", value=21.3, timestamp=1476191999000)
9 changes: 6 additions & 3 deletions examples/explicit_retention_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from inflow import Client

client = Client('http://username:pass@localhost:8086/databasename',
retention_policy='rp_four_weeks')
client = Client(
"http://username:pass@localhost:8086",
db="databasename",
retention_policy="rp_four_weeks",
)

client.write('temperature', value=21.3)
client.write("temperature", value=21.3)
2 changes: 1 addition & 1 deletion examples/query_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from inflow import Client

client = Client('http://username:pass@localhost:8086/databasename')
client = Client("http://username:pass@localhost:8086", db="databasename")
results = client.query('SELECT * FROM "temperatures"')
# Results will contain a list of dicts for each returned measurement.
4 changes: 2 additions & 2 deletions examples/query_measurements_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

from inflow import Client

client = Client('http://username:pass@localhost:8086/databasename')
results = client.query('SELECT * FROM "temperatures"', epoch='s')
client = Client("http://username:pass@localhost:8086", db="databasename")
results = client.query('SELECT * FROM "temperatures"', epoch="s")
5 changes: 3 additions & 2 deletions examples/single_write.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from inflow import Client
client = Client('http://username:pass@localhost:8086/databasename')
client.write('temperature', value=21.3)

client = Client("http://username:pass@localhost:8086", db="databasename")
client.write("temperature", value=21.3)
11 changes: 4 additions & 7 deletions examples/single_write_more.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

from inflow import Client

client = Client('http://username:pass@localhost:8086/databasename')
client = Client("http://username:pass@localhost:8086", db="databasename")

client.write(
'temperature',
tags={
'location': 'groningen',
'sensor_type': 'ni1000'
},
"temperature",
tags={"location": "groningen", "sensor_type": "ni1000"},
value=21.3,
timestamp=1475845863
timestamp=1475845863,
)
5 changes: 3 additions & 2 deletions examples/single_write_retention_policy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from inflow import Client
client = Client('http://username:pass@localhost:8086/databasename')
client.write('temperature', value=21.3, retention_policy='rp_four_weeks')

client = Client("http://username:pass@localhost:8086", db="databasename")
client.write("temperature", value=21.3, retention_policy="rp_four_weeks")
5 changes: 2 additions & 3 deletions examples/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from inflow import Client

client = Client('http://username:pass@localhost:8086/databasename',
timeout=0.01)
client = Client("http://username:pass@localhost:8086", db="databasename", timeout=0.01)

client.write('temperature', value=21.3)
client.write("temperature", value=21.3)
19 changes: 9 additions & 10 deletions examples/write_multiple_succinct.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

from inflow import Client

client = Client('http://username:pass@localhost:8086/databasename')
client = Client("http://username:pass@localhost:8086", db="databasename")

temperature = dict(
name='temperature',
tags={
'location': 'groningen',
'sensor_type': 'ni1000'
}
name="temperature", tags={"location": "groningen", "sensor_type": "ni1000"}
)

client.write(temperature, [
{'value': 21.3, 'timestamp': 1475845863},
{'value': 20.1, 'timestamp': 1475846182}
])
client.write(
temperature,
[
{"value": 21.3, "timestamp": 1475845863},
{"value": 20.1, "timestamp": 1475846182},
],
)
9 changes: 2 additions & 7 deletions examples/write_multiple_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

from inflow import Client

client = Client('http://username:pass@localhost:8086/databasename')
client = Client("http://username:pass@localhost:8086", db="databasename")

client.write(
'temperature',
timestamp=1475846182,
lower_sensor=20.9,
upper_sensor=23.2
)
client.write("temperature", timestamp=1475846182, lower_sensor=20.9, upper_sensor=23.2)
38 changes: 17 additions & 21 deletions examples/write_multiple_verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@

from inflow import Client, Measurement

client = Client('http://username:pass@localhost:8086/databasename')
client = Client("http://username:pass@localhost:8086", db="databasename")

client.write([
Measurement(
name='temperature',
tags={
'location': 'groningen',
'sensor_type': 'ni1000'
},
value=21.3,
timestamp=1475845863
),
Measurement(
name='temperature',
tags={
'location': 'groningen',
'sensor_type': 'ni1000'
},
value=20.1,
timestamp=1475848864
)
])
client.write(
[
Measurement(
name="temperature",
tags={"location": "groningen", "sensor_type": "ni1000"},
value=21.3,
timestamp=1475845863,
),
Measurement(
name="temperature",
tags={"location": "groningen", "sensor_type": "ni1000"},
value=20.1,
timestamp=1475848864,
),
]
)
8 changes: 4 additions & 4 deletions inflow/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
class Client(WriteMixin):
""" The InfluxDB client. """

def __init__(self, uri, precision='s', retention_policy=None, timeout=None):
self.connection = Connection(uri, precision, retention_policy, timeout)
def __init__(self, uri, db=None, precision='s', retention_policy=None, timeout=None):
self.connection = Connection(uri, db, precision, retention_policy, timeout)

def write_func(self, measurement, **kwargs):
return self.connection.write(measurement, **kwargs)

def session(self, autocommit_every=None, retention_policy=None):
return Session(self.connection, autocommit_every, retention_policy)

def query(self, query, epoch=None):
return self.connection.query(query, epoch)
def query(self, query, epoch=None, db=None):
return self.connection.query(query, epoch, db)
Loading