Skip to content

Commit f8705f9

Browse files
authored
feat(client): add support for context managers (influxdata#816)
* feat(client): add support for context managers * chore(CHANGELOG): rebase against master
1 parent f7f30b5 commit f8705f9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2323
- Add gzip compression for post and response data (#732 thx @KEClaytor)
2424
- Add support for chunked responses in ResultSet (#753 and #538 thx @hrbonz && @psy0rz)
2525
- Add support for empty string fields (#766 thx @gregschrock)
26+
- Add support for context managers to InfluxDBClient (#721 thx @JustusAdam)
2627

2728
### Changed
2829
- Clean up stale CI config (#755)
@@ -37,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3738
- Update client to type-set UDP port to int (#651 thx @yifeikong)
3839
- Update batched writing support for all iterables (#746 thx @JayH5)
3940
- Update SeriesHelper to enable class instantiation when not initialized (#772 thx @ocworld)
41+
- Update UDP test case to add proper timestamp to datapoints (#808 thx @shantanoo-desai)
4042

4143
### Removed
4244

influxdb/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class InfluxDBClient(object):
3535
connect to InfluxDB. Requests can be made to InfluxDB directly through
3636
the client.
3737
38+
The client supports the use as a `context manager
39+
<https://docs.python.org/3/reference/datamodel.html#context-managers>`_.
40+
3841
:param host: hostname to connect to InfluxDB, defaults to 'localhost'
3942
:type host: str
4043
:param port: port to connect to InfluxDB, defaults to 8086
@@ -78,6 +81,7 @@ class InfluxDBClient(object):
7881
requests Session, defaults to None
7982
:type session: requests.Session
8083
:raises ValueError: if cert is provided but ssl is disabled (set to False)
84+
8185
"""
8286

8387
def __init__(self,
@@ -165,6 +169,14 @@ def __init__(self,
165169

166170
self._gzip = gzip
167171

172+
def __enter__(self):
173+
"""Enter function as used by context manager."""
174+
pass
175+
176+
def __exit__(self, _exc_type, _exc_value, _traceback):
177+
"""Exit function as used by context manager."""
178+
self.close()
179+
168180
@property
169181
def _baseurl(self):
170182
return self.__baseurl

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy