elasticsearch-dbapi
A DBAPI and SQLAlchemy dialect for Elasticsearch
What it is and what it does
elasticsearch-dbapi bridges Python's standard database API and SQLAlchemy ORM to Elasticsearch and OpenSearch clusters. It translates SQL queries into the native SQL APIs provided by Elastic X-Pack (for Elasticsearch) and OpenSearch SQL plugins, enabling read-only access to indexed data through familiar Python database patterns. The library supports Elasticsearch 7.x, 8.x (with compatibility mode), and OpenSearch 2.x, with special support for AWS Elasticsearch Service.
You can use it three ways: directly via DBAPI (connect and cursor), through SQLAlchemy's raw execute interface, or via SQLAlchemy's ORM reflection to introspect indices as tables. Connection strings follow RFC-1738 and accept transport parameters like http_compress and timeout. The library defaults to a 10000-row fetch limit and UTC timezone but allows both to be customized per connection.
Use it for:
- Query Elasticsearch indices using standard SQL syntax from Python without learning the native query DSL.
- Integrate Elasticsearch data into SQLAlchemy-based applications for ORM-style table reflection and queries.
- Connect AWS Elasticsearch Service (OpenSearch) clusters to Python analytics or reporting tools via DBAPI.
- Build data pipelines that treat Elasticsearch indices as queryable tables alongside traditional SQL databases.
- Prototype or migrate applications from SQL databases to Elasticsearch by reusing existing DBAPI-compatible code.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides DBAPI (PEP-249) and SQLAlchemy dialect access to Elasticsearch and OpenSearch clusters via SQL, enabling read-only queries against these search engines.
Yes. The package is actively maintained, has no known security vulnerabilities, low install friction, and fills a genuine gap for developers needing SQL access to Elasticsearch or OpenSearch. The permissive Apache License, Version 2.0 poses no adoption barrier. Install it if you need to query Elasticsearch/OpenSearch via SQL or SQLAlchemy; skip it only if you prefer native query DSLs or have no Elasticsearch infrastructure.
Install
elasticsearch-dbapi on PyPI
pip
pip install elasticsearch-dbapiuv
uv add elasticsearch-dbapipoetry
poetry add elasticsearch-dbapiInstalling elasticsearch-dbapi
Before you install
Low friction install with four runtime dependencies (elasticsearch, opensearch-py, packaging, sqlalchemy). Active maintenance with a recent commit on 2026-05-07 and 120 repository stars.
License in practice
Apache License, Version 2.0 (permissive) allows use in most projects, including commercial ones, with minimal restrictions beyond attribution and liability disclaimers.
Quickstart
pip install elasticsearch-dbapi
from sqlalchemy.engine import create_engine
engine = create_engine('elasticsearch+http://localhost:9200/')
rows = engine.connect().execute('select * from flights LIMIT 10')
print([row for row in rows])
Elasticsearch or OpenSearch cluster must be running and accessible at the specified host/port; for Elasticsearch 8.x, set ELASTIC_CLIENT_APIVERSIONING=1 in your Python environment.
Verify before relying
- Whether the library handles connection pooling or concurrent query execution efficiently at scale.
- Performance characteristics when querying large result sets near the 10000-row default fetch limit.
- Compatibility with Elasticsearch 8.x beyond the documented ELASTIC_CLIENT_APIVERSIONING environment variable requirement.
Package facts
| License | Apache License, Version 2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — elasticsearch, opensearch-py, packaging, sqlalchemy |
| Maintenance | actively maintained — 99 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,386,514/month — #3,972 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: elasticsearch_dbapi-0.2.13-py3-none-any.whl
Tags
More Front-Ends packages
SQLAlchemy is a Python SQL toolkit and Object…
permissive · top 100 on PyPI
psycopg2-binarypsycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
alembicAlembic generates and manages database schema…
permissive · top 1,000 on PyPI
weaviate-clientA Python client library for connecting to and…
permissive · top 1,000 on PyPI
databricks-sql-connectorA Python client library that connects to…
permissive · top 1,000 on PyPI
psycopgPsycopg 3 is a PostgreSQL database adapter for…
copyleft · top 1,000 on PyPI
databricks-dbapiProvides a DBAPI 2.0 connection interface and…
permissive · top 15,000 on PyPI
dbapiCommand-line client for interacting with Douban…
permissive · top 15,000 on PyPI
pinotdbProvides Python DB-API and SQLAlchemy dialect…
permissive · top 1,000 on PyPI
sqlalchemy-databricksProvides a SQLAlchemy dialect that connects to…
permissive · top 15,000 on PyPI
presto-python-clientProvides a Python DBAPI-compatible client to…
permissive · top 5,000 on PyPI
sqlalchemy-jdbcapiSQLAlchemy dialect for JDBC and ODBC database…
permissive · top 15,000 on PyPI
ibm-db-saSQLAlchemy dialect adapter that enables Python…
permissive · top 15,000 on PyPI
sqlalchemy-solrProvides a SQLAlchemy dialect that allows you…
permissive · top 15,000 on PyPI
opensearch-pyPython client library for connecting to and…
permissive · top 1,000 on PyPI
shillelaghShillelagh lets you query APIs, files,…
permissive · top 5,000 on PyPI