def __init__(self, host: str = 'localhost', port: int = 8086,
username: Optional[str] = None, password: Optional[str] = None,
db: str = 'testdb', database: Optional[str] = None,
loop: asyncio.BaseEventLoop = None,
log_level: int = 30, mode: str = 'async'):
"""
The AsyncInfluxDBClient object holds information necessary to interact with InfluxDB.
It is async by default, but can also be used as a sync/blocking client and even generate
Pandas DataFrames from queries.
The three main public methods are the three endpoints of the InfluxDB API, namely:
1) AsyncInfluxDBClient.ping
2) AsyncInfluxDBClient.write
3) AsyncInfluxDBClient.query
See each of the above methods documentation for further usage details.
See also: https://docs.influxdata.com/influxdb/v1.2/tools/api/
:param host: Hostname to connect to InfluxDB.
:param port: Port to connect to InfluxDB.
:param username: Username to use to connect to InfluxDB.
:param password: User password.
:param db: Default database to be used by the client.
:param database: Default database to be used by the client.
This field is for argument consistency with the official InfluxDB Python client.
:param loop: Event loop used for processing HTTP requests.
:param log_level: Logging level. The lower the more verbose. Defaults to INFO (30).
:param mode: Mode in which client should run.
Available options are: 'async', 'blocking' and 'dataframe'.
- 'async': Default mode. Each query/request to the backend will
- 'blocking': Behaves in sync/blocking fashion, similar to the official InfluxDB-Python client.
- 'dataframe': Behaves in a sync/blocking fashion, but parsing results into Pandas DataFrames.
Similar to InfluxDB-Python's `DataFrameClient`.
"""
self._logger = self._make_logger(log_level)
self._loop = asyncio.get_event_loop() if loop is None else loop
self._auth = aiohttp.BasicAuth(username, password) if username and password else None
self._session = aiohttp.ClientSession(loop=self._loop, auth=self._auth)
self._url = f'http://{host}:{port}/{{endpoint}}'
self.host = host
self.port = port
self.db = database or db
self.mode = mode
if mode not in {'async', 'blocking', 'dataframe'}:
raise ValueError('Invalid mode')
评论列表
文章目录