Skip to content

Commit

Permalink
#2: Improved README
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar committed Aug 9, 2019
1 parent 4f45e2b commit 33bb665
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,45 @@ for row in csv_result:

### Writes

The [WriteApiClient](https://github.com/bonitoo-io/influxdb-client-python/blob/master/influxdb2/client/write_api.py) supports synchronous, asynchronous and batching writes into InfluxDB 2.0 and could be configured by `WriteOptions`:
The [WriteApi](https://github.com/bonitoo-io/influxdb-client-python/blob/master/influxdb2/client/write_api.py) supports synchronous, asynchronous and batching writes into InfluxDB 2.0.
The data should be passed as a InfluxDB Line Protocol, Data Point or Observable stream.

_The default instance of `WriteApi` use batching._

#### Batching

The batching is configurable by `write_options`:

| Property | Description | Default Value |
| --- | --- | --- |
| [**write_type**](#write_type) | how the client writes data; allowed values: `batching`, `asynchronous`, `synchronous`| `batching` |
| **batch_size** | the number of data point to collect in batch | `1000` |
| **flush_interval** | the number of milliseconds before the batch is written | `1000` |
| **jitter_interval** | the number of milliseconds to increase the batch flush interval by a random amount | `0` |
| **retry_interval** | the number of milliseconds to retry unsuccessful write. The retry interval is used when the InfluxDB server does not specify "Retry-After" header. | `1000` |

##### write_type
* `batching` - data are writes in batches defined by `batch_size`, `flush_interval`, ...
* `asynchronous` - data are writes in asynchronous HTTP request
* `synchronous` - data are writes in synchronous HTTP request

##### Asynchronous client
Data are writes in an asynchronous HTTP request.

```python
from influxdb2.client.influxdb_client import InfluxDBClient
from influxdb2.client.write_api import ASYNCHRONOUS

client = InfluxDBClient(url="http://localhost:9999/api/v2", token="my-token-123", org="my-org", debug=True)
write_client = client.write_api(write_options=ASYNCHRONOUS)
```

##### Synchronous client

Data are writes in a synchronous HTTP request.

```python
from influxdb2.client.influxdb_client import InfluxDBClient
from influxdb2.client.write_api import SYNCHRONOUS

client = InfluxDBClient(url="http://localhost:9999/api/v2", token="my-token-123", org="my-org", debug=True)
write_client = client.write_api(write_options=SYNCHRONOUS)
```

#### How to efficiently import large dataset

Expand Down
8 changes: 4 additions & 4 deletions influxdb2/client/write/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from influxdb2.domain.write_precision import WritePrecision

EPOCH = UTC.localize(datetime.utcfromtimestamp(0))

DEFAULT_WRITE_PRECISION = WritePrecision.NS

class Point(object):
"""
Expand All @@ -27,9 +27,9 @@ def __init__(self, measurement_name):
self._fields = {}
self._name = measurement_name
self._time = None
self._write_precision = WritePrecision.NS
self._write_precision = DEFAULT_WRITE_PRECISION

def time(self, time, write_precision=WritePrecision.NS):
def time(self, time, write_precision=DEFAULT_WRITE_PRECISION):
self._write_precision = write_precision
self._time = time
return self
Expand Down Expand Up @@ -111,7 +111,7 @@ def escape_value(value):
return value.translate(str.maketrans({'\"': r"\"", "\\": r"\\"}))


def _convert_timestamp(timestamp, precision=WritePrecision.NS):
def _convert_timestamp(timestamp, precision=DEFAULT_WRITE_PRECISION):
if isinstance(timestamp, Integral):
return timestamp # assume precision is correct if timestamp is int

Expand Down
4 changes: 1 addition & 3 deletions influxdb2/client/write_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from rx.scheduler import ThreadPoolScheduler
from rx.subject import Subject

from influxdb2 import WritePrecision
from influxdb2.client.abstract_client import AbstractClient
from influxdb2.client.write.point import Point
from influxdb2.client.write.point import Point, DEFAULT_WRITE_PRECISION
from influxdb2.rest import ApiException

logger = logging.getLogger(__name__)
Expand All @@ -37,7 +36,6 @@ def __init__(self, write_type=WriteType.batching, batch_size=1_000, flush_interv
self.write_scheduler = write_scheduler


DEFAULT_WRITE_PRECISION = WritePrecision.NS
SYNCHRONOUS = WriteOptions(write_type=WriteType.synchronous)
ASYNCHRONOUS = WriteOptions(write_type=WriteType.asynchronous)

Expand Down

0 comments on commit 33bb665

Please sign in to comment.