PyDruid is a Python connector for Apache Druid, providing a simple API to create, execute, and analyze Druid queries. It can parse query results into Pandas DataFrame objects for seamless integration with the SciPy stack. The library offers both synchronous and asynchronous clients, implements the Python DB API 2.0, and includes a SQLAlchemy dialect. The current version is 0.6.9, and it maintains an active development and release cadence.
pip install pydruidVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to establish a connection to Druid using the Python DB API 2.0 interface and execute a basic SQL query. Ensure your Druid cluster is running and accessible at the specified host and port. Connection parameters can be provided via environment variables DRUID_HOST, DRUID_PORT, DRUID_PATH, and DRUID_SCHEME.
Pass `context={'sqlQueryId': '...', 'header': True}` in your query parameters, or ensure your Druid configuration forces header output if applicable for all queries.Upgrade pydruid to version 0.6.0 or newer to ensure compatibility with modern Python versions.
After executing a query (e.g., `query_result = client.timeseries(...)`), call `query_result.export_pandas()` or `query_result.export_tsv(dest_path)` instead.
Install `pydruid` with the `[sqlalchemy]` extra: `pip install pydruid[sqlalchemy]`.
Install the library using pip: `pip install pydruid` or `pip install pydruid[pandas]` if planning to use Pandas integration.
Verify the Druid query syntax, ensure the `url` and `endpoint` provided to the `PyDruid` client are correct (e.g., `http://localhost:8082/druid/v2/sql/` for SQL queries), and check Druid server logs for more specific error details.
Check the Druid server status and logs to ensure it's running and responding with valid JSON. This can also happen if the client is pointed to an incorrect URL that serves non-JSON content, like a human-readable web page.
Ensure you are using a `pydruid` version compatible with your Python 3 environment, or update your Python 2 code to use the Python 3 `urllib` syntax. This specific `AttributeError` was common in older `pydruid` versions run on Python 3.