U vi94@sdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZed ZGd d d eZdS) zuInfluxDBClientAsync is client for API defined in https://github.com/influxdata/openapi/blob/master/contracts/oss.yml.N) PingService) _BaseClientDeleteApiAsync) QueryOptions QueryApiAsync) PointSettings WriteApiAsyncz,influxdb_client.client.influxdb_client_asynccseZdZdZd"eeddfdd Zddd d Zddd d Zd dZe d#edddZ e d$ddZ e dddZ edddZedddZefeedddZefedddZedd d!ZZS)%InfluxDBClientAsyncz.InfluxDBClientAsync is client for InfluxDB v2.N'F)tokenorgreturnc stjf||||||dd|tjdddkrBddlm}n ddlm}z|} | dkrftd Wn0tk rdd lm } d } | d| d YnXdd l m } | f|j |j |jd||_dS)ap Initialize defaults. :param url: InfluxDB server API url (ex. http://localhost:8086). :param token: ``token`` to authenticate to the InfluxDB 2.x :param org: organization name (used as a default in Query, Write and Delete API) :param debug: enable verbose logging of http requests :param timeout: The maximal number of milliseconds for the whole HTTP request including connection establishment, request sending and response reading. It can also be a :class:`~aiohttp.ClientTimeout` which is directly pass to ``aiohttp``. :param enable_gzip: Enable Gzip compression for http requests. Currently, only the "Write" and "Query" endpoints supports the Gzip compression. :key bool verify_ssl: Set this to false to skip verifying SSL certificate when calling API from https server. :key str ssl_ca_cert: Set this to customize the certificate file to verify the peer. :key str cert_file: Path to the certificate that will be used for mTLS authentication. :key str cert_key_file: Path to the file contains private key for mTLS certificate. :key str cert_key_password: String or function which returns password for decrypting the mTLS private key. :key ssl.SSLContext ssl_context: Specify a custom Python SSL Context for the TLS/ mTLS handshake. Be aware that only delivered certificate/ key files or an SSL Context are possible. :key str proxy: Set this to configure the http proxy to be used (ex. http://localhost:3128) :key str proxy_headers: A dictionary containing headers that will be sent to the proxy. Could be used for proxy authentication. :key int connection_pool_maxsize: The total number of simultaneous connections. Defaults to "multiprocessing.cpu_count() * 5". :key bool auth_basic: Set this to true to enable basic authentication when talking to a InfluxDB 1.8.x that does not use auth-enabled but is protected by a reverse proxy with basic authentication. (defaults to false, don't set to true when talking to InfluxDB 2) :key str username: ``username`` to authenticate via username and password credentials to the InfluxDB 2.x :key str password: ``password`` to authenticate via username and password credentials to the InfluxDB 2.x :key bool allow_redirects: If set to ``False``, do not follow HTTP redirects. ``True`` by default. :key int max_redirects: Maximum number of HTTP redirects to follow. ``10`` by default. :key dict client_session_kwargs: Additional configuration arguments for :class:`~aiohttp.ClientSession` :key type client_session_type: Type of aiohttp client to use. Useful for third party wrappers like ``aiohttp-retry``. :class:`~aiohttp.ClientSession` by default. :key list[str] profilers: list of enabled Flux profilers zaiohttp.client)urlrrdebugtimeout enable_gzipZhttp_client_loggerN)r)get_running_loop)_get_running_loopzno running event loop) InfluxDBErrorzjThe async client should be initialised inside async coroutine otherwise there can be unexpected behaviour.)responsemessage)ApiClientAsync) configuration header_name header_value)super__init__sys version_infoasynciorr RuntimeErrorZ!influxdb_client.client.exceptionsrZ_async.api_clientrconfZauth_header_nameZauth_header_value api_client) selfrrrrrrkwargsrlooprrr __class__]/opt/alt/python38/lib/python3.8/site-packages/influxdb_client/client/influxdb_client_async.pyr"s,'     zInfluxDBClientAsync.__init__)rcs|S)zb Enter the runtime context related to this object. return: self instance r.r)r.r.r/ __aenter__SszInfluxDBClientAsync.__aenter__cs|IdHdSzShutdown the client.N)close)r)exc_typeexctbr.r.r/ __aexit__[szInfluxDBClientAsync.__aexit__cs |jr|jIdHd|_dSr2)r(r3r0r.r.r/r3_szInfluxDBClientAsync.close config.ini) config_filecKstjf|||d|S)a Configure client via configuration file. The configuration has to be under 'influx' section. :param config_file: Path to configuration file :param debug: Enable verbose logging of http requests :param enable_gzip: Enable Gzip compression for http requests. Currently, only the "Write" and "Query" endpoints supports the Gzip compression. :key config_name: Name of the configuration section of the configuration file :key str proxy_headers: A dictionary containing headers that will be sent to the proxy. Could be used for proxy authentication. :key urllib3.util.retry.Retry retries: Set the default retry strategy that is used for all HTTP requests except batching writes. As a default there is no one retry strategy. :key ssl.SSLContext ssl_context: Specify a custom Python SSL Context for the TLS/ mTLS handshake. Be aware that only delivered certificate/ key files or an SSL Context are possible. The supported formats: - https://docs.python.org/3/library/configparser.html - https://toml.io/en/ - https://www.json.org/json-en.html Configuration options: - url - org - token - timeout, - verify_ssl - ssl_ca_cert - cert_file - cert_key_file - cert_key_password - connection_pool_maxsize - auth_basic - profilers - proxy config.ini example:: [influx2] url=http://localhost:8086 org=my-org token=my-token timeout=6000 connection_pool_maxsize=25 auth_basic=false profilers=query,operator proxy=http:proxy.domain.org:8080 [tags] id = 132-987-655 customer = California Miner data_center = ${env.data_center} config.toml example:: [influx2] url = "http://localhost:8086" token = "my-token" org = "my-org" timeout = 6000 connection_pool_maxsize = 25 auth_basic = false profilers="query, operator" proxy = "http://proxy.domain.org:8080" [tags] id = "132-987-655" customer = "California Miner" data_center = "${env.data_center}" config.json example:: { "url": "http://localhost:8086", "token": "my-token", "org": "my-org", "active": true, "timeout": 6000, "connection_pool_maxsize": 55, "auth_basic": false, "profilers": "query, operator", "tags": { "id": "132-987-655", "customer": "California Miner", "data_center": "${env.data_center}" } } )r9rr)r Z_from_config_file)clsr9rrr*r.r.r/from_config_filees \ z$InfluxDBClientAsync.from_config_filecKstjf||d|S)a8 Configure client via environment properties. :param debug: Enable verbose logging of http requests :param enable_gzip: Enable Gzip compression for http requests. Currently, only the "Write" and "Query" endpoints supports the Gzip compression. :key str proxy: Set this to configure the http proxy to be used (ex. http://localhost:3128) :key str proxy_headers: A dictionary containing headers that will be sent to the proxy. Could be used for proxy authentication. :key urllib3.util.retry.Retry retries: Set the default retry strategy that is used for all HTTP requests except batching writes. As a default there is no one retry strategy. :key ssl.SSLContext ssl_context: Specify a custom Python SSL Context for the TLS/ mTLS handshake. Be aware that only delivered certificate/ key files or an SSL Context are possible. Supported environment properties: - INFLUXDB_V2_URL - INFLUXDB_V2_ORG - INFLUXDB_V2_TOKEN - INFLUXDB_V2_TIMEOUT - INFLUXDB_V2_VERIFY_SSL - INFLUXDB_V2_SSL_CA_CERT - INFLUXDB_V2_CERT_FILE - INFLUXDB_V2_CERT_KEY_FILE - INFLUXDB_V2_CERT_KEY_PASSWORD - INFLUXDB_V2_CONNECTION_POOL_MAXSIZE - INFLUXDB_V2_AUTH_BASIC - INFLUXDB_V2_PROFILERS - INFLUXDB_V2_TAG )rr)r Z_from_env_properties)r:rrr*r.r.r/from_env_propertiess!z'InfluxDBClientAsync.from_env_propertiesc sVt|j}z|IdHWdStk rP}ztd||W5d}~XYnXdS)zc Return the status of InfluxDB instance. :return: The status of InfluxDB. NTz!Unexpected error during /ping: %s)rr(get_ping_async Exceptionloggerr)r) ping_serviceexr.r.r/pings  zInfluxDBClientAsync.pingcs&t|j}|jddIdH}||S)zq Return the version of the connected InfluxDB Server. :return: The version of InfluxDB. F)Z_return_http_data_onlyN)rr(r=Zresponse_header)r)r@rr.r.r/versions zInfluxDBClientAsync.versioncst|j}|IdHS)zw Return the build type of the connected InfluxDB Server. :return: The type of InfluxDB build. N)rr(Zbuild_type_async)r)r@r.r.r/builds zInfluxDBClientAsync.build) query_optionsrcCs t||S)z Create an asynchronous Query API instance. :param query_options: optional query api configuration :return: Query api instance r)r)rEr.r.r/ query_api szInfluxDBClientAsync.query_apicCs t||dS)a Create an asynchronous Write API instance. Example: .. code-block:: python from influxdb_client_async import InfluxDBClientAsync # Initialize async/await instance of Write API async with InfluxDBClientAsync(url="http://localhost:8086", token="my-token", org="my-org") as client: write_api = client.write_api() :param point_settings: settings to store default tags :return: write api instance )influxdb_clientpoint_settingsr )r)rHr.r.r/ write_apiszInfluxDBClientAsync.write_apicCst|S)z` Get the asynchronous delete metrics API instance. :return: delete api rr0r.r.r/ delete_api'szInfluxDBClientAsync.delete_api)NNNr F)r8NF)NF)__name__ __module__ __qualname____doc__strr"r1r7r3 classmethodr;r<boolrBrCrDrrrFr r rIrrJ __classcell__r.r.r,r/r s"@^ "   r )rNloggingr#rGrZinfluxdb_client.client._baserZ'influxdb_client.client.delete_api_asyncrZ influxdb_client.client.query_apirZ&influxdb_client.client.query_api_asyncrZ influxdb_client.client.write_apir Z&influxdb_client.client.write_api_asyncr getLoggerr?r r.r.r.r/s