# OpcUaClient

## class OpcUaClient

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object "(in Python v3.15)")

A shared synchronous OPC UA session, created with `connect()`.

Nodes and subscriptions retain this client. Explicit disconnection affects
every handle; dropping the original Python variable alone does not.
Use a context manager to disconnect when leaving a scope.

Examples

```
>>> from instro.opcua import OpcUaClient
>>> with OpcUaClient.connect("opc.tcp://localhost:4840") as client:
...     print(client.objects.node_id)
```

Attributes

| [`objects`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.OpcUaClient.md#instro.opcua.OpcUaClient.objects "instro.opcua.OpcUaClient.objects") | The standard ObjectsFolder, without a server read. |
| --- | --- |
| [`types`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.OpcUaClient.md#instro.opcua.OpcUaClient.types "instro.opcua.OpcUaClient.types") | The standard TypesFolder, without a server read. |
| [`views`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.OpcUaClient.md#instro.opcua.OpcUaClient.views "instro.opcua.OpcUaClient.views") | The standard ViewsFolder, without a server read. |

Methods

| [`connect`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.OpcUaClient.md#instro.opcua.OpcUaClient.connect "instro.opcua.OpcUaClient.connect") | Connect to an endpoint using native OPC UA connection and retry settings. |
| --- | --- |
| [`disable_reconnects`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.OpcUaClient.md#instro.opcua.OpcUaClient.disable_reconnects "instro.opcua.OpcUaClient.disable_reconnects") | Disable native reconnect attempts for the existing session. |
| [`disconnect`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.OpcUaClient.md#instro.opcua.OpcUaClient.disconnect "instro.opcua.OpcUaClient.disconnect") | Disconnect the shared OPC UA session. |
| [`enable_reconnects`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.OpcUaClient.md#instro.opcua.OpcUaClient.enable_reconnects "instro.opcua.OpcUaClient.enable_reconnects") | Enable native reconnect attempts for the existing session. |
| [`get_node`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.OpcUaClient.md#instro.opcua.OpcUaClient.get_node "instro.opcua.OpcUaClient.get_node") | Resolve one Node from RootFolder. |
| [`read_nodes`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.OpcUaClient.md#instro.opcua.OpcUaClient.read_nodes "instro.opcua.OpcUaClient.read_nodes") | Read the same attribute from several nodes in a batch. |
| [`subscribe`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.OpcUaClient.md#instro.opcua.OpcUaClient.subscribe "instro.opcua.OpcUaClient.subscribe") | Monitor one attribute across a group of nodes. |

### static connect( endpoint_url, *, identity=None, security_policy=Ellipsis, security_mode=Ellipsis, application_name=Ellipsis, application_uri=Ellipsis, product_uri='', create_sample_keypair=False, ignore_clock_skew=False, recreate_subscriptions=True, trust_server_certs=False, verify_server_certs=True, certificate_path=None, private_key_path=None, pki_dir=None, preferred_locales=None, channel_lifetime=None, session_retry_limit=None, session_retry_initial_s=None, session_retry_max_s=None, keep_alive_interval_s=None, max_array_length=None, max_byte_string_length=None, max_chunk_count=None, max_chunk_size=None, max_incoming_chunk_size=None, max_message_size=None, max_string_length=None, max_failed_keep_alive_count=None, request_timeout_s=None, publish_timeout_s=None, min_publish_interval_ms=None, recreate_monitored_items_chunk=None, session_name='Instro OPC UA Client', session_timeout=None, session_nonce_length=None, allow_plaintext_creds=False, )

Connect to an endpoint using native OPC UA connection and retry settings.

Duration parameters accept finite nonnegative numbers in the units named
by each parameter. Passing None for an optional override uses the native
default. All settings after `endpoint_url` are keyword-only.

Waiting releases the GIL. If Python interrupts the wait, cleanup starts
in the background.

Parameters:
:   - **endpoint_url** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

      OPC UA server endpoint URL.
    - **identity** ([*IdentityToken*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.IdentityToken.md#instro.opcua.IdentityToken "instro.opcua.IdentityToken") *|* *None*)

      User identity; `None` is anonymous.
    - **security_policy** ([*SecurityPolicy*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.SecurityPolicy.md#instro.opcua.types.SecurityPolicy "instro.opcua.types.SecurityPolicy") *|* [*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

      Policy value, canonical name,
      supported AES alias, or full policy URI. Defaults to `None` policy.
    - **security_mode** ([*MessageSecurityMode*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.MessageSecurityMode.md#instro.opcua.types.MessageSecurityMode "instro.opcua.types.MessageSecurityMode") *|* [*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

      `None`, `Sign`, or
      `SignAndEncrypt`; names are case-insensitive. Defaults to `None` mode.
    - **application_name** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

      Application display name. Defaults to
      `Nominal OPC UA Client`.
    - **application_uri** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

      Application URI. Defaults to `urn:nominal:opcua-client`.
    - **product_uri** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

      Product URI. Defaults to an empty string.
    - **create_sample_keypair** ([*bool*](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)"))

      Generate a sample application key pair
      when native provisioning requires it. Defaults to `False`.
    - **certificate_path** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") *|* [*PathLike*](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.15)")*[*[*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")*]* *|* *None*)

      Application certificate
      path relative to the PKI directory; supply with `private_key_path`. Defaults to `None`.
    - **private_key_path** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") *|* [*PathLike*](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.15)")*[*[*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")*]* *|* *None*)

      Application private key
      path relative to the PKI directory; supply with `certificate_path`. Defaults to `None`.
    - **trust_server_certs** ([*bool*](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)"))

      Automatically place server certificates in the
      native trusted store. Defaults to `False`.
    - **verify_server_certs** ([*bool*](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)"))

      Verify hostname, application URI, and validity dates.
      Trust and key-length checks still apply when false. Defaults to `True`.
    - **pki_dir** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") *|* [*PathLike*](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.15)")*[*[*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")*]* *|* *None*)

      Native PKI directory.
      Defaults to the native PKI location when omitted.
    - **preferred_locales** ([*list*](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)")*[*[*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")*]* *|* *None*)

      Preferred locale IDs, in order.
    - **channel_lifetime** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Requested secure channel lifetime in milliseconds.
    - **session_retry_limit** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Native retry limit: `-1` for unlimited,
      `0` for none, or a positive count.
    - **session_retry_initial_s** ([*float*](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)") *|* *None*)

      Initial reconnect backoff in seconds.
    - **session_retry_max_s** ([*float*](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)") *|* *None*)

      Maximum reconnect backoff in seconds.
    - **keep_alive_interval_s** ([*float*](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)") *|* *None*)

      Session keep-alive interval in seconds.
    - **max_array_length** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Maximum decoded array length. Zero permits no elements.
    - **max_byte_string_length** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Maximum decoded byte-string length in bytes.
      Zero permits no bytes.
    - **max_chunk_count** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Maximum chunks per message. Zero means unlimited.
    - **max_chunk_size** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Maximum outgoing chunk size in bytes.
    - **max_incoming_chunk_size** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Maximum incoming chunk size in bytes.
    - **max_message_size** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Maximum outgoing message size in bytes.
      Zero means unlimited.
    - **max_string_length** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Maximum decoded string size in bytes.
      Zero permits no string content.
    - **max_failed_keep_alive_count** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Failed keep-alive limit before native closure.
      Zero disables this limit.
    - **request_timeout_s** ([*float*](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)") *|* *None*)

      Ordinary request timeout in seconds.
    - **publish_timeout_s** ([*float*](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)") *|* *None*)

      Publish request timeout in seconds.
    - **min_publish_interval_ms** ([*float*](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)") *|* *None*)

      Client minimum publish interval in
      milliseconds.
    - **ignore_clock_skew** ([*bool*](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)"))

      Ignore clock skew in native transport handling.
      Defaults to `False`.
    - **recreate_monitored_items_chunk** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Maximum monitored items per
      restoration request.
    - **recreate_subscriptions** ([*bool*](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)"))

      Let native recovery transfer or recreate
      subscriptions. Defaults to `True`.
    - **session_name** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") *|* *None*)

      Requested session name. Defaults to
      `Instro OPC UA Client`. Passing None uses the native default.
    - **session_timeout** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Requested session timeout in milliseconds.
    - **session_nonce_length** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      CreateSession nonce length in bytes.
    - **allow_plaintext_creds** ([*bool*](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)"))

      Allow sending a plaintext password for
      username authentication. Defaults to `False`.

Returns:
:   *OpcUaClient* – An activated shared client.

Raises:
:   - [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – A keyword or argument type is unsupported.
    - [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – A setting is invalid.
    - [**OverflowError**](https://docs.python.org/3/builtins/exceptions.html#OverflowError "(in Python v3.15)") – An integer is outside the range of its connection setting.
    - [**OpcUaError**](https://dev.nominal.io/instro/ref/protocols/opcua.md#instro.opcua.OpcUaError "instro.opcua.OpcUaError") – Native connection or activation fails.
    - [**KeyboardInterrupt**](https://docs.python.org/3/builtins/exceptions.html#KeyboardInterrupt "(in Python v3.15)") – Python interrupts the connection wait.

### disable_reconnects()

Disable native reconnect attempts for the existing session.

### disconnect()

Disconnect the shared OPC UA session.

Admitted operations finish first. The caller that takes the session waits
for shutdown with the GIL released and defers Python signals. A concurrent
caller can return before shutdown finishes. During recovery, the client can
stop without sending a CloseSession request.

Raises:
:   [**OpcUaError**](https://dev.nominal.io/instro/ref/protocols/opcua.md#instro.opcua.OpcUaError "instro.opcua.OpcUaError") – Native shutdown reports a failure.

### enable_reconnects()

Enable native reconnect attempts for the existing session.

This does not restart a native event loop that has already finished.

### get_node(path)

Resolve one Node from RootFolder.

Parameters:
:   **path** ([*RelativePath*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.RelativePath.md#instro.opcua.types.RelativePath "instro.opcua.types.RelativePath") *|* [*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

    Nonempty path starting at RootFolder.

Returns:
:   *Node* – The single fully resolved local Node.

Raises:
:   [**OpcUaError**](https://dev.nominal.io/instro/ref/protocols/opcua.md#instro.opcua.OpcUaError "instro.opcua.OpcUaError") – Translation fails, is ambiguous, or leaves unresolved or
    out-of-server targets.

### objects

The standard ObjectsFolder, without a server read.

Type:
:   [*Node*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.Node.md#instro.opcua.Node "instro.opcua.Node")

### read_nodes(nodes, attribute=None)

Read the same attribute from several nodes in a batch.

The client splits translation and read requests as needed to fit its
decoded array limit.

Parameters:
:   - **nodes** (*Iterable**[*[*Node*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.Node.md#instro.opcua.Node "instro.opcua.Node") *|* [*RelativePath*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.RelativePath.md#instro.opcua.types.RelativePath "instro.opcua.types.RelativePath") *|* [*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")*]*)

      Nodes belonging to this client
      or browse paths starting at RootFolder.
    - **attribute** ([*AttributeId*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.AttributeId.md#instro.opcua.types.AttributeId "instro.opcua.types.AttributeId") *|* [*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* [*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") *|* *None*)

      Attribute to read. Defaults to Value.

Returns:
:   *list[AttributeValue]* – One sample per node in input order.

### subscribe( nodes, publishing_interval_ms, *, attribute=None, lifetime_count=60, max_keep_alive_count=20, max_notifications_per_publish=0, priority=0, publishing_enabled=True, sampling_interval_ms=Ellipsis, queue_size=0, discard_oldest=False, poll_interval_ms=2000.0, )

Monitor one attribute across a group of nodes.

If Python interrupts setup after allocation starts, native setup runs to
completion and any resulting subscription is closed in the background.

Parameters:
:   - **nodes** (*Iterable**[*[*Node*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.Node.md#instro.opcua.Node "instro.opcua.Node") *|* [*RelativePath*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.RelativePath.md#instro.opcua.types.RelativePath "instro.opcua.types.RelativePath") *|* [*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")*]*)

      Consumed once before native
      allocation. Paths are rooted at RootFolder; duplicate or foreign
      Nodes are rejected. Results retain these rooted Nodes.
    - **publishing_interval_ms** ([*float*](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)"))

      Requested publishing interval in milliseconds.
      Values at or below zero request the fastest supported publishing interval.
      The server request uses whole milliseconds.
    - **attribute** ([*AttributeId*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.AttributeId.md#instro.opcua.types.AttributeId "instro.opcua.types.AttributeId") *|* [*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* [*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") *|* *None*)

      Group attribute, default Value.
    - **lifetime_count** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"))

      Requested subscription lifetime count, default 60.
    - **max_keep_alive_count** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"))

      Requested keep-alive count, default 20.
    - **max_notifications_per_publish** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"))

      Zero means no requested limit.
    - **priority** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"))

      Native unsigned byte priority, default zero.
    - **publishing_enabled** ([*bool*](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)"))

      Enable native publishing, default True.
    - **sampling_interval_ms** ([*float*](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)"))

      Milliseconds. Negative values (default -1) inherit
      the publishing interval. Zero requests the fastest practical sampling.
    - **queue_size** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"))

      Native monitored-item queue request, default zero.
    - **discard_oldest** ([*bool*](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)"))

      Native monitored-item discard policy, default False.
    - **poll_interval_ms** ([*float*](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)") *|* *None*)

      Positive fallback polling period in
      milliseconds. Defaults to 2000 ms. None disables fallback reads.

Returns:
:   *Subscription* – Iterator over retained Node and AttributeValue pairs.

Raises:
:   - [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – A value, Node group, or resolved duplicate is invalid.
    - [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – A keyword or iterable element has an unsupported type.
    - [**OverflowError**](https://docs.python.org/3/builtins/exceptions.html#OverflowError "(in Python v3.15)") – An integer is outside the range of its subscription setting.
    - [**ExceptionGroup**](https://docs.python.org/3/builtins/exceptions.html#ExceptionGroup "(in Python v3.15)") – Monitored-item rejections in request order, each carrying
      the Node identifier and original status. Setup is rolled back first.
    - [**OpcUaError**](https://dev.nominal.io/instro/ref/protocols/opcua.md#instro.opcua.OpcUaError "instro.opcua.OpcUaError") – A native setup service fails. Cleanup cannot hide this error.

### types

The standard TypesFolder, without a server read.

Type:
:   [*Node*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.Node.md#instro.opcua.Node "instro.opcua.Node")

### views

The standard ViewsFolder, without a server read.

Type:
:   [*Node*](https://dev.nominal.io/instro/ref/protocols/instro.opcua.Node.md#instro.opcua.Node "instro.opcua.Node")
