File: nodes.rst

package info (click to toggle)
python-elastic-transport 9.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 644 kB
  • sloc: python: 6,652; makefile: 18
file content (62 lines) | stat: -rw-r--r-- 1,475 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Nodes
=====

.. py:currentmodule:: elastic_transport

Configuring nodes
-----------------

.. autoclass:: elastic_transport::NodeConfig
   :members:


Node classes
------------

.. autoclass:: Urllib3HttpNode
   :members:

.. autoclass:: RequestsHttpNode
   :members:

.. autoclass:: AiohttpHttpNode
   :members:

.. autoclass:: HttpxAsyncHttpNode
   :members:

Custom node classes
-------------------

You can define your own node class like so:

.. code-block:: python

   from typing import Optional
   from elastic_transport import Urllib3HttpNode, NodeConfig, ApiResponseMeta, HttpHeaders
   from elastic_transport.client_utils import DefaultType, DEFAULT

   class CustomHttpNode(Urllib3HttpNode):
      def perform_request(
         self,
         method: str,
         target: str,
         body: Optional[bytes] = None,
         headers: Optional[HttpHeaders] = None,
         request_timeout: Union[DefaultType, Optional[float]] = DEFAULT,
      ) -> Tuple[ApiResponseMeta, bytes]:
         # Define your HTTP request method here...

and once you have a custom node class you can pass the class to :class:`elastic_transport.Transport` or an API client like so:

.. code-block:: python

   # Example using a Transport instance:
   from elastic_transport import Transport

   transport = Transport(..., node_class=CustomHttpNode)

   # Example using an API client:
   from elasticsearch import Elasticsearch

   client = Elasticsearch(..., node_class=CustomHttpNode)