diff --git a/influxdb/client.py b/influxdb/client.py index 5e39f490..3ebf7ab0 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -18,6 +18,7 @@ import requests.exceptions from six.moves import xrange from six.moves.urllib.parse import urlparse +import gzip from influxdb.line_protocol import make_lines, quote_ident, quote_literal from influxdb.resultset import ResultSet @@ -89,6 +90,7 @@ def __init__(self, pool_size=10, path='', cert=None, + compression=False ): """Construct a new InfluxDBClient object.""" self.__host = host @@ -98,6 +100,13 @@ def __init__(self, self._database = database self._timeout = timeout self._retries = retries + if compression is True: + self._compression = 9 + else: + self._compression = compression + + assert self._compression is False or \ + (self._compression >= 0 and self._compression <= 9) self._verify_ssl = verify_ssl @@ -354,6 +363,10 @@ def write(self, data, params=None, expected_response_code=204, data = [data] data = ('\n'.join(data) + '\n').encode('utf-8') + if self._compression is not False: + data = gzip.compress(data, self._compression) + headers['Content-Encoding'] = 'gzip' + self.request( url="write", method='POST',