{"library":"questdb","title":"QuestDB Python Client","description":"The `questdb` library is the official Python client for QuestDB, a high-performance open-source SQL database for time-series and analytics. It provides efficient ingestion of data via InfluxDB Line Protocol (ILP) over TCP or HTTP, supporting various Python data types, Pandas DataFrames, and NumPy arrays. The current version is 4.1.0, and releases are typically feature-driven, often aligning with new QuestDB server capabilities.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install questdb"],"cli":null},"imports":["from questdb.client import Sender"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport time\nfrom questdb.client import Sender\nfrom datetime import datetime, timezone\n\n# Configure QuestDB connection (ILP over HTTP)\n# Use os.environ.get for security and flexibility in deployment\nQDB_HOST = os.environ.get(\"QDB_HOST\", \"localhost\")\nQDB_PORT = os.environ.get(\"QDB_PORT\", \"9000\")\nQDB_AUTH = os.environ.get(\"QDB_AUTH\", \"\") # Format: \"username:token\"\n\nconf = f'http::addr={QDB_HOST}:{QDB_PORT};'\nif QDB_AUTH:\n    conf += f'auth={QDB_AUTH};' # Assumes auth syntax for QuestDB 7.0+\nelse:\n    print(\"Warning: QDB_AUTH environment variable not set. Connecting without authentication.\")\n\ntry:\n    with Sender.from_conf(conf) as sender:\n        # Ingest a single row of data\n        sender.row(\n            \"sensor_data\",\n            columns={\n                \"location\": \"london\",\n                \"temperature\": 15.5,\n                \"humidity\": 70,\n                \"event_time\": datetime.now(timezone.utc)\n            },\n            at=datetime.now(timezone.utc) # QuestDB timestamp column\n        )\n\n        # Ingest another row, demonstrating nanosecond precision (client v4.0.0+)\n        # Note: Requires QuestDB server 9.1.0+ for nanosecond TIMESTAMP_NS type\n        nanos_timestamp = int(time.time_ns()) # Current time in nanoseconds\n        sender.row(\n            \"sensor_data\",\n            columns={\n                \"location\": \"paris\",\n                \"temperature\": 18.2,\n                \"humidity\": 65,\n                \"event_time\": datetime.now(timezone.utc)\n            },\n            at=nanos_timestamp # This sends nanosecond precision\n        )\n\n        sender.flush() # Ensure all buffered data is sent\n        print(\"Data sent successfully to QuestDB!\")\n\nexcept Exception as e:\n    print(f\"Failed to send data: {e}\")\n    print(f\"Please ensure QuestDB server is running and accessible at http://{QDB_HOST}:{QDB_PORT}\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the `Sender` using a configuration string for ILP over HTTP and ingest two rows of data. It also highlights the support for nanosecond precision timestamps introduced in version 4.0.0. The connection details can be configured via environment variables for easy deployment.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}