{"id":1513,"library":"influxdb-client","title":"InfluxDB Python Client","description":"The official Python client library for InfluxDB 2.0+, providing comprehensive API access for writing, querying (Flux), and managing InfluxDB resources. It is actively maintained with frequent minor releases, typically on a monthly to bi-monthly cadence.","status":"active","version":"1.50.0","language":"python","source_language":"en","source_url":"https://github.com/influxdata/influxdb-client-python","tags":["database","time-series","influxdb","flux","data-ingestion","data-query"],"install":[{"cmd":"pip install influxdb-client","lang":"bash","label":"Install core client"},{"cmd":"pip install \"influxdb-client[pandas]\"","lang":"bash","label":"Install with Pandas support"}],"dependencies":[{"reason":"Required for DataFrame integration (e.g., writing/reading Pandas DataFrames to/from InfluxDB).","package":"pandas","optional":true}],"imports":[{"symbol":"InfluxDBClient","correct":"from influxdb_client import InfluxDBClient"},{"symbol":"Point","correct":"from influxdb_client import Point"},{"symbol":"WriteOptions","correct":"from influxdb_client import WriteOptions"},{"note":"SYNCHRONOUS is part of the write_api module, not top-level.","wrong":"from influxdb_client import SYNCHRONOUS","symbol":"SYNCHRONOUS","correct":"from influxdb_client.client.write_api import SYNCHRONOUS"}],"quickstart":{"code":"import os\nfrom influxdb_client import InfluxDBClient, Point, WriteOptions\nfrom influxdb_client.client.write_api import SYNCHRONOUS\n\n# Configuration from environment variables for security and flexibility\nINFLUXDB_URL = os.environ.get('INFLUXDB_URL', 'http://localhost:8086')\nINFLUXDB_TOKEN = os.environ.get('INFLUXDB_TOKEN', 'YOUR_INFLUXDB_TOKEN')\nINFLUXDB_ORG = os.environ.get('INFLUXDB_ORG', 'YOUR_INFLUXDB_ORG')\nINFLUXDB_BUCKET = os.environ.get('INFLUXDB_BUCKET', 'YOUR_INFLUXDB_BUCKET')\n\nif 'YOUR_INFLUXDB_TOKEN' in INFLUXDB_TOKEN or 'YOUR_INFLUXDB_ORG' in INFLUXDB_ORG or 'YOUR_INFLUXDB_BUCKET' in INFLUXDB_BUCKET:\n    print(\"WARNING: Please set INFLUXDB_URL, INFLUXDB_TOKEN, INFLUXDB_ORG, and INFLUXDB_BUCKET environment variables or update the quickstart code.\")\n\nprint(f\"Connecting to InfluxDB at {INFLUXDB_URL} for org '{INFLUXDB_ORG}'\")\n\nwith InfluxDBClient(url=INFLUXDB_URL, token=INFLUXDB_TOKEN, org=INFLUXDB_ORG) as client:\n    # 1. Write data point\n    write_api = client.write_api(write_options=WriteOptions(batch_size=1, flush_interval=1_000, write_type=SYNCHRONOUS))\n    point = Point(\"my_measurement\") \\\n        .tag(\"location\", \"us-west\") \\\n        .field(\"temperature\", 25.0) \\\n        .field(\"humidity\", 60.5)\n\n    try:\n        write_api.write(bucket=INFLUXDB_BUCKET, record=point)\n        print(f\"Successfully wrote point: {point.to_line_protocol()}\")\n    except Exception as e:\n        print(f\"Error writing point: {e}\")\n\n    # 2. Query data using Flux\n    query_api = client.query_api()\n    query = f'from(bucket: \"{INFLUXDB_BUCKET}\") |> range(start: -1h) |> filter(fn: (r) => r._measurement == \"my_measurement\")'\n\n    print(f\"Executing Flux query:\\n{query}\")\n    try:\n        tables = query_api.query(query, org=INFLUXDB_ORG)\n        for table in tables:\n            for record in table.records:\n                print(f\"  Queried: {record.get_measurement()}, {record.get_field()}=\"{record.get_value()}\" at {record.get_time()}\")\n    except Exception as e:\n        print(f\"Error querying data: {e}\")\n\nprint(\"Client closed.\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the InfluxDBClient, write a single data point using the synchronous write API, and then query data using a basic Flux query. Remember to replace placeholder environment variables with your actual InfluxDB 2.x connection details (URL, Token, Organization, Bucket)."},"warnings":[{"fix":"Ensure you are connecting to an InfluxDB 2.x instance or use the `influxdb` client library for InfluxDB 1.x.","message":"This client is specifically designed for InfluxDB 2.0+ (Flux API) and is NOT compatible with InfluxDB 1.x HTTP API endpoints. Trying to connect to an InfluxDB 1.x instance will result in authentication or API endpoint errors.","severity":"breaking","affected_versions":"All versions"},{"fix":"When creating the write API, use `client.write_api(write_options=WriteOptions(write_type=SYNCHRONOUS))` for guaranteed immediate writes. For high-throughput scenarios, carefully configure batch size and flush interval.","message":"The default write API is asynchronous (batching and buffering). For immediate writes, ensure you specify `write_type=SYNCHRONOUS` in `WriteOptions`. Not doing so can lead to data not appearing immediately in queries or being lost if the application crashes before the buffer is flushed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `influxdb-client` version 1.42.0 or newer to ensure correct handling of `NaN` values in DataFrames. Alternatively, pre-process DataFrames to handle or remove `NaN` values before writing.","message":"Older versions (pre-1.42.0) had issues with serializing Pandas DataFrames containing `NaN` (Not a Number) values, leading to errors or incorrect data storage.","severity":"gotcha","affected_versions":"<1.42.0"},{"fix":"Ensure your environment uses Python 3.7 or a more recent version (e.g., Python 3.8, 3.9, 3.10, 3.11, 3.12).","message":"The client requires Python 3.7 or newer. Using older Python versions will result in `SyntaxError` or `ImportError` due to modern language features and type hinting.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `influxdb-client` version 1.45.0 or newer to benefit from these fixes and avoid potential warnings or compatibility issues with newer Python versions.","message":"Several internal `urllib` calls and `datetime` timezone helper functions were replaced or refactored in recent versions to avoid deprecated Python functions. While this mainly affects internal workings, it's good practice to update.","severity":"deprecated","affected_versions":"<1.45.0 for datetime, <1.43.0 for urllib"},{"fix":"Review example code for proper f-string syntax. Ensure inner quoted strings are properly escaped (e.g., `\\\"`) or use different quote types for the f-string itself (e.g., `f'...'` for the outer string if inner parts need `\"`).","message":"Example or test scripts may contain a `SyntaxError` related to incorrect f-string formatting, particularly when attempting to embed quoted string literals directly within an f-string that uses the same quote type. For instance, using `f\"... {variable}=\"{value}\" ...\"` will cause a `SyntaxError`.","severity":"gotcha","affected_versions":"All versions (where such examples exist)"}],"env_vars":null,"search_vec":"'2.0':11 'access':15 'activ':26 'api':14 'bi':38 'bi-month':37 'cadenc':40 'client':3,7 'comprehens':13 'data':48,51 'data-ingest':47 'data-queri':50 'databas':41 'flux':19,46 'frequent':29 'influxdb':1,10,22,45 'ingest':49 'librari':8 'maintain':27 'manag':21 'minor':30 'month':35,39 'offici':5 'provid':12 'python':2,6 'queri':18,52 'releas':31 'resourc':23 'seri':44 'time':43 'time-seri':42 'typic':32 'write':17","created_at":"2026-04-09T03:51:10.044515+00:00","updated_at":"2026-04-16T15:44:23.382380+00:00","problems":[{"fix":"Ensure you have the correct client installed for InfluxDB 2.x and that your Python environment is active. Use `pip install influxdb-client` or `pip install 'influxdb-client[ciso]'` for faster date parsing.","cause":"This error often occurs when the `influxdb-client` library is not installed, or when there's a confusion between the `influxdb` (for InfluxDB 1.x) and `influxdb-client` (for InfluxDB 2.x) packages, or if using an incorrect Python environment.","error":"ModuleNotFoundError: No module named 'influxdb_client'"},{"fix":"Verify that your InfluxDB URL, authentication token, and organization ID are correct and have the appropriate read/write permissions for the target bucket. Ensure environment variables are correctly loaded if you're using `os.environ.get()` to retrieve credentials.","cause":"This 'Unauthorized access' error (HTTP 401) indicates that the token, organization ID, or URL provided to the `InfluxDBClient` is incorrect or lacks the necessary permissions to perform the requested operation.","error":"Reason: Unauthorized HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.7.0', 'X-Platform-Error-Code': 'unauthorized', 'Date': 'Wed, 17 May 2023 15:03:50 GMT', 'Content-Length': '55'}) HTTP response body: {\"code\":\"unauthorized\",\"message\":\"unauthorized access\"}"},{"fix":"Ensure that `url`, `token`, and `org` are always provided with valid string values during `InfluxDBClient` initialization. Double-check that all required configuration parameters are correctly supplied and not `None`.","cause":"This `AttributeError` typically occurs when the `token` or `org` parameters are `None` during the initialization of `InfluxDBClient`, leading to a partially initialized client object that lacks expected attributes. It can also be caused by trying to use a method that does not exist in the version of the client library being used or when mixing InfluxDB 1.x client code with InfluxDB 2.x client initialization.","error":"AttributeError: 'InfluxDBClient' object has no attribute 'api_client'"},{"fix":"Increase the `timeout` parameter during `InfluxDBClient` initialization. The timeout is specified in milliseconds. For example, `InfluxDBClient(url=..., token=..., org=..., timeout=20000)` sets a 20-second timeout.","cause":"This error occurs when the client's HTTP request to the InfluxDB server exceeds the configured timeout duration, often due to large queries, slow network conditions, or an overly aggressive (low) timeout setting.","error":"Read timed out. (read timeout=0)"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.50.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://docs.influxdata.com/influxdb/v2.0/api-guide/client-libraries/python/","github":"https://github.com/influxdata/influxdb-client-python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/influxdb-client/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","http-networking","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":"verified"}}