U vilE@sdZddlmZddlZddlZddlmZmZmZm Z m Z m Z ddl m Z ddlmZddlmZddlmZdd lmZdd lmZdd lmZmZdd lmZdd lmZddlm Z m!Z!m"Z"e#dZ$Gddde Z%dS)zpInfluxDBClient is client for API defined in https://github.com/influxdata/influxdb/blob/master/http/swagger.yml.)absolute_importN) HealthCheck HealthServiceReady ReadyService PingServiceInvokableScriptsApi) _BaseClientAuthorizationsApi BucketsApi DeleteApi LabelsApiOrganizationsApi)QueryApi QueryOptionsTasksApiUsersApi)WriteApi WriteOptions PointSettingsz&influxdb_client.client.influxdb_clientcsTeZdZdZd6eeeddfdd Zdd Zd d Ze d7ed ddZ e d8ddZ e e fedddZefeedddZedddZddZddZedddZedd d!Zedd"d#Zedd$d%Zedd&d'Z e!dd(d)Z"e#dd*d+Z$e%dd,d-Z&edd.d/Z'edd0d1Z(e)dd2d3Z*e+dd4d5Z,Z-S)9InfluxDBClientz)InfluxDBClient is client for InfluxDB v2.N'F)tokenorg default_tagsreturnc sNtjf|||||||dd|ddlm} | |j|j|j|jd|_dS)a6 Initialize defaults. :param url: InfluxDB server API url (ex. http://localhost:8086). :param token: ``token`` to authenticate to the InfluxDB API :param debug: enable verbose logging of http requests :param timeout: HTTP client timeout setting for a request specified in milliseconds. If one number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts. :param enable_gzip: Enable Gzip compression for http requests. Currently, only the "Write" and "Query" endpoints supports the Gzip compression. :param org: organization name (used as a default in Query, Write and Delete API) :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: Number of connections to save that can be reused by urllib3. Defaults to "multiprocessing.cpu_count() * 5". :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 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 list[str] profilers: list of enabled Flux profilers urllib3)urlrdebugtimeout enable_gzipr r!Zhttp_client_logger) ApiClient) configuration header_name header_valueretriesN) super__init__Z_sync.api_clientr)confZauth_header_nameZauth_header_valuer- api_client) selfr$rr%r&r'r r!kwargsr) __class__W/opt/alt/python38/lib/python3.8/site-packages/influxdb_client/client/influxdb_client.pyr/s$  zInfluxDBClient.__init__cCs|S)u Enter the runtime context related to this object. It will bind this method’s return value to the target(s) specified in the `as` clause of the statement. return: self instance r6r2r6r6r7 __enter__Fs zInfluxDBClient.__enter__cCs |dS)zEExit the runtime context related to this object and close the client.N)close)r2exc_type exc_value tracebackr6r6r7__exit__QszInfluxDBClient.__exit__ 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}" } } )r@r%r')rZ_from_config_file)clsr@r%r'r3r6r6r7from_config_fileUs\zInfluxDBClient.from_config_filecKstjf||d|S)a7 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 )r%r')rZ_from_env_properties)rAr%r'r3r6r6r7from_env_propertiess z"InfluxDBClient.from_env_properties)r"cKstf|||d|S)a Create Write API instance. Example: .. code-block:: python from influxdb_client import InfluxDBClient from influxdb_client.client.write_api import SYNCHRONOUS # Initialize SYNCHRONOUS instance of WriteApi with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org") as client: write_api = client.write_api(write_options=SYNCHRONOUS) If you would like to use a **background batching**, you have to configure client like this: .. code-block:: python from influxdb_client import InfluxDBClient # Initialize background batching instance of WriteApi with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org") as client: with client.write_api() as write_api: pass There is also possibility to use callbacks to notify about state of background batches: .. code-block:: python from influxdb_client import InfluxDBClient from influxdb_client.client.exceptions import InfluxDBError class BatchingCallback(object): def success(self, conf: (str, str, str), data: str): print(f"Written batch: {conf}, data: {data}") def error(self, conf: (str, str, str), data: str, exception: InfluxDBError): print(f"Cannot write batch: {conf}, data: {data} due: {exception}") def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError): print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org") as client: callback = BatchingCallback() with client.write_api(success_callback=callback.success, error_callback=callback.error, retry_callback=callback.retry) as write_api: pass :param write_options: Write API configuration :param point_settings: settings to store default tags :key success_callback: The callable ``callback`` to run after having successfully written a batch. The callable must accept two arguments: - `Tuple`: ``(bucket, organization, precision)`` - `str`: written data **[batching mode]** :key error_callback: The callable ``callback`` to run after having unsuccessfully written a batch. The callable must accept three arguments: - `Tuple`: ``(bucket, organization, precision)`` - `str`: written data - `Exception`: an occurred error **[batching mode]** :key retry_callback: The callable ``callback`` to run after retryable error occurred. The callable must accept three arguments: - `Tuple`: ``(bucket, organization, precision)`` - `str`: written data - `Exception`: an retryable error **[batching mode]** :return: write api instance )influxdb_client write_optionspoint_settings)r)r2rErFr3r6r6r7 write_apisQzInfluxDBClient.write_api) query_optionsr"cCs t||S)z Create an Query API instance. :param query_options: optional query api configuration :return: Query api instance )r)r2rHr6r6r7 query_api(szInfluxDBClient.query_apicCst|S)zj Create an InvokableScripts API instance. :return: InvokableScripts API instance )rr8r6r6r7invokable_scripts_api1sz$InfluxDBClient.invokable_scripts_apicCs |dSzShutdown the client.N)__del__r8r6r6r7r:9szInfluxDBClient.closecCs|jr|jd|_dSrK)r1rLr8r6r6r7rL=s zInfluxDBClient.__del__cCst|S)zO Create the Bucket API instance. :return: buckets api r r8r6r6r7 buckets_apiCszInfluxDBClient.buckets_apicCst|S)z^ Create the Authorizations API instance. :return: authorizations api r r8r6r6r7authorizations_apiKsz!InfluxDBClient.authorizations_apicCst|S)zL Create the Users API instance. :return: users api rr8r6r6r7 users_apiSszInfluxDBClient.users_apicCst|S)z\ Create the Organizations API instance. :return: organizations api rr8r6r6r7organizations_api[sz InfluxDBClient.organizations_apicCst|S)zL Create the Tasks API instance. :return: tasks api rr8r6r6r7 tasks_apicszInfluxDBClient.tasks_apicCst|S)zN Create the Labels API instance. :return: labels api rr8r6r6r7 labels_apikszInfluxDBClient.labels_apic Csbtdtt|j}z|}|WStk r\}ztdt|ddWYSd}~XYnXdS)zN Get the health of an instance. :return: HealthCheck z1This method is deprecated. Call 'ping()' instead.ZinfluxdbZfail)namemessagestatusN) warningswarnDeprecationWarningrr1Z get_health Exceptionrstr)r2Zhealth_servicehealther6r6r7r[ss  zInfluxDBClient.healthc CsRt|j}z|WdStk rL}ztd|WYdSd}~XYnXdS)zc Return the status of InfluxDB instance. :return: The status of InfluxDB. Tz!Unexpected error during /ping: %sFN)rr1Zget_pingrYloggerr%)r2 ping_serviceexr6r6r7pings  zInfluxDBClient.pingcCs t|j}|jdd}||S)zq Return the version of the connected InfluxDB Server. :return: The version of InfluxDB. F)Z_return_http_data_only)rr1Zget_ping_with_http_infoZresponse_header)r2r^responser6r6r7versions  zInfluxDBClient.versioncCst|j}|S)zw Return the build type of the connected InfluxDB Server. :return: The type of InfluxDB build. )rr1Z build_type)r2r^r6r6r7builds zInfluxDBClient.buildcCst|j}|S)zP Get The readiness of the InfluxDB 2.0. :return: Ready )rr1Z get_ready)r2Z ready_servicer6r6r7readys zInfluxDBClient.readycCst|S)zS Get the delete metrics API instance. :return: delete api rr8r6r6r7 delete_apiszInfluxDBClient.delete_api)NNrFNN)r?NF)NF).__name__ __module__ __qualname____doc__rZdictr/r9r> classmethodrBrCrrrrGrrrIrrJr:rLr rMr rNrrOrrPrrQrrRrr[boolr`rbrcrrdrre __classcell__r6r6r4r7rs<+ ] !S    r)&ri __future__rloggingrVrDrrrrrrZinfluxdb_client.client._baser Z)influxdb_client.client.authorizations_apir Z!influxdb_client.client.bucket_apir Z!influxdb_client.client.delete_apirZ!influxdb_client.client.labels_apirZ(influxdb_client.client.organizations_apirZ influxdb_client.client.query_apirrZ influxdb_client.client.tasks_apirZ influxdb_client.client.users_apirZ influxdb_client.client.write_apirrr getLoggerr]rr6r6r6r7s