{"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":"en","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"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}