OpenSearch Python Client
Official Python client for OpenSearch — AWS's Apache 2.0 fork of Elasticsearch 7.10. Current version: 3.1.0 (Mar 2026). API is nearly identical to elasticsearch-py v7 but NOT interchangeable — different package, different import. OpenSearch 1.x deprecated May 2025. v3.0 client released alongside OpenSearch 3.0. Major footgun: developers import elasticsearch instead of opensearch_py by mistake. Also compatible with Amazon OpenSearch Service (AWS managed).
Warnings
- breaking Package name is 'opensearch-py' but import is 'from opensearchpy import OpenSearch' (no hyphen). pip install opensearch-py; import opensearchpy.
- gotcha opensearch-py and elasticsearch-py have near-identical APIs but are NOT interchangeable. Different packages, different auth patterns, different SSL defaults. Cannot swap imports.
- gotcha Amazon OpenSearch Service (AWS managed) requires AWS SigV4 auth — not basic_auth. Use opensearch-py with requests-aws4auth or boto3 credentials.
- gotcha OpenSearch 1.x deprecated May 2025. Amazon OpenSearch Service still supports 1.x and 2.x but new projects should target 2.x+.
- gotcha Unlike elasticsearch-py v8+, opensearch-py still uses the body= parameter pattern (elasticsearch v7 style). Don't apply elasticsearch v8 named-param migration to opensearch-py.
Install
-
pip install opensearch-py
Imports
- OpenSearch
from opensearchpy import OpenSearch client = OpenSearch( hosts=[{'host': 'localhost', 'port': 9200}], http_auth=('admin', 'admin'), use_ssl=True, verify_certs=False, # dev only ssl_show_warn=False ) # Index — same pattern as elasticsearch-py v7 client.index( index='my-index', body={'name': 'Alice', 'age': 30}, id='1' ) # Search resp = client.search( index='my-index', body={'query': {'match': {'name': 'Alice'}}} ) - AsyncOpenSearch
from opensearchpy import AsyncOpenSearch import asyncio async def main(): client = AsyncOpenSearch( hosts=[{'host': 'localhost', 'port': 9200}], http_auth=('admin', 'admin'), use_ssl=False ) resp = await client.search( index='my-index', body={'query': {'match_all': {}}} ) await client.close() asyncio.run(main())
Quickstart
# pip install opensearch-py
from opensearchpy import OpenSearch
client = OpenSearch(
hosts=[{'host': 'localhost', 'port': 9200}],
http_auth=('admin', 'admin'),
use_ssl=False
)
# Create index
client.indices.create(
index='products',
body={
'mappings': {
'properties': {
'name': {'type': 'text'},
'price': {'type': 'float'}
}
}
}
)
# Index document
client.index(index='products', id='1', body={'name': 'Widget', 'price': 9.99})
# Search
resp = client.search(
index='products',
body={'query': {'match': {'name': 'Widget'}}}
)
for hit in resp['hits']['hits']:
print(hit['_source'])