# Setting Connection Timeout Value for opensearch-py

**URL:** <https://forum.opensearch.org/t/setting-connection-timeout-value-for-opensearch-py/8796>\
**Category:** OpenSearch Client Libraries\
**Tags:** opensearch-js\
**Created:** [March 2, 2022, 5:21pm UTC](https://forum.opensearch.org/t/setting-connection-timeout-value-for-opensearch-py/8796 "2022-03-02T17:21:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrick](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/patrick/32/2919_2.png) [@patrick](https://forum.opensearch.org/u/patrick)\
**Post date:** [March 2, 2022, 5:21pm UTC](https://forum.opensearch.org/t/setting-connection-timeout-value-for-opensearch-py/8796/1 "2022-03-02T17:21:54Z")

</div>

Hi, looking for a way to set a fail-fast timeout on connections to OpenSearch. I’ve tried setting timeout=5 from the client instantiation, but i’m still seeing 10 second exceptions, as set in

`https://github.com/opensearch-project/opensearch-py/blob/main/opensearchpy/connection/base.py`

```auto
from opensearchpy import OpenSearch

    opensearch_client = OpenSearch(
        ... 
        timeout = 5
    )

```

---

<div class="post-metadata">

**Author:** ![patrick](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/patrick/32/2919_2.png) [@patrick](https://forum.opensearch.org/u/patrick)\
**Post date:** [March 19, 2022, 2:03pm UTC](https://forum.opensearch.org/t/setting-connection-timeout-value-for-opensearch-py/8796/2 "2022-03-19T14:03:48Z")

</div>

> [@patrick](#):
>
> seeing 10 second exceptions, as

It’s been two weeks with no input , so what i’ve done is a quick requests connection test before opening opensearch to see about basic reachability. In this way i can fast-fail for not reachable, and still maintain a long timeout for search queries that take longer.

---

<div class="post-metadata">

**Author:** ![asadullahmkhan](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@asadullahmkhan](https://forum.opensearch.org/u/asadullahmkhan)\
**Post date:** [October 8, 2025, 12:35am UTC](https://forum.opensearch.org/t/setting-connection-timeout-value-for-opensearch-py/8796/3 "2025-10-08T00:35:07Z")

</div>

Way late but the way to do it is described here: [https://stackoverflow.com/a/77191094/4021308](https://stackoverflow.com/a/77191094/4021308)

```auto
search(
 index=index,
       body=search_body,
       params={
         "timeout":30, 
         "scroll": scroll, 
         "ignore": ignore, 
         "size": size
       }
)

```

basically you need to add it to the `params` per request
