skillfed

elasticsearch-dbapi

A DBAPI and SQLAlchemy dialect for Elasticsearch

elasticsearch-dbapi v0.2.13 1.4M downloads/30d#3,972 on PyPI120
Permissive license Apache License, Version 2.0 Active released

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-dbapi

uv

uv add elasticsearch-dbapi

poetry

poetry add elasticsearch-dbapi

Installing 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

Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12

Tags

elasticsearch sql querysqlalchemy elasticsearch dialectdbapi elasticsearch connectoropensearch sql accesselasticsearch python sqlaws opensearch sql driverelasticsearch query interface
elasticsearchsqlalchemy-dialectopensearch

More Front-Ends packages