OpcUaClient#

class OpcUaClient#

Bases: object

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

The standard ObjectsFolder, without a server read.

types

The standard TypesFolder, without a server read.

views

The standard ViewsFolder, without a server read.

Methods

connect

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

disable_reconnects

Disable native reconnect attempts for the existing session.

disconnect

Disconnect the shared OPC UA session.

enable_reconnects

Enable native reconnect attempts for the existing session.

get_node

Resolve one Node from RootFolder.

read_nodes

Read the same attribute from several nodes in a batch.

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)

    OPC UA server endpoint URL.

  • identity (IdentityToken | None)

    User identity; None is anonymous.

  • security_policy (SecurityPolicy | str)

    Policy value, canonical name, supported AES alias, or full policy URI. Defaults to None policy.

  • security_mode (MessageSecurityMode | str)

    None, Sign, or SignAndEncrypt; names are case-insensitive. Defaults to None mode.

  • application_name (str)

    Application display name. Defaults to Nominal OPC UA Client.

  • application_uri (str)

    Application URI. Defaults to urn:nominal:opcua-client.

  • product_uri (str)

    Product URI. Defaults to an empty string.

  • create_sample_keypair (bool)

    Generate a sample application key pair when native provisioning requires it. Defaults to False.

  • certificate_path (str | PathLike[str] | None)

    Application certificate path relative to the PKI directory; supply with private_key_path. Defaults to None.

  • private_key_path (str | PathLike[str] | None)

    Application private key path relative to the PKI directory; supply with certificate_path. Defaults to None.

  • trust_server_certs (bool)

    Automatically place server certificates in the native trusted store. Defaults to False.

  • verify_server_certs (bool)

    Verify hostname, application URI, and validity dates. Trust and key-length checks still apply when false. Defaults to True.

  • pki_dir (str | PathLike[str] | None)

    Native PKI directory. Defaults to the native PKI location when omitted.

  • preferred_locales (list[str] | None)

    Preferred locale IDs, in order.

  • channel_lifetime (int | None)

    Requested secure channel lifetime in milliseconds.

  • session_retry_limit (int | None)

    Native retry limit: -1 for unlimited, 0 for none, or a positive count.

  • session_retry_initial_s (float | None)

    Initial reconnect backoff in seconds.

  • session_retry_max_s (float | None)

    Maximum reconnect backoff in seconds.

  • keep_alive_interval_s (float | None)

    Session keep-alive interval in seconds.

  • max_array_length (int | None)

    Maximum decoded array length. Zero permits no elements.

  • max_byte_string_length (int | None)

    Maximum decoded byte-string length in bytes. Zero permits no bytes.

  • max_chunk_count (int | None)

    Maximum chunks per message. Zero means unlimited.

  • max_chunk_size (int | None)

    Maximum outgoing chunk size in bytes.

  • max_incoming_chunk_size (int | None)

    Maximum incoming chunk size in bytes.

  • max_message_size (int | None)

    Maximum outgoing message size in bytes. Zero means unlimited.

  • max_string_length (int | None)

    Maximum decoded string size in bytes. Zero permits no string content.

  • max_failed_keep_alive_count (int | None)

    Failed keep-alive limit before native closure. Zero disables this limit.

  • request_timeout_s (float | None)

    Ordinary request timeout in seconds.

  • publish_timeout_s (float | None)

    Publish request timeout in seconds.

  • min_publish_interval_ms (float | None)

    Client minimum publish interval in milliseconds.

  • ignore_clock_skew (bool)

    Ignore clock skew in native transport handling. Defaults to False.

  • recreate_monitored_items_chunk (int | None)

    Maximum monitored items per restoration request.

  • recreate_subscriptions (bool)

    Let native recovery transfer or recreate subscriptions. Defaults to True.

  • session_name (str | None)

    Requested session name. Defaults to Instro OPC UA Client. Passing None uses the native default.

  • session_timeout (int | None)

    Requested session timeout in milliseconds.

  • session_nonce_length (int | None)

    CreateSession nonce length in bytes.

  • allow_plaintext_creds (bool)

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

Returns:

OpcUaClient – An activated shared client.

Raises:
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 – 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 | str)

Nonempty path starting at RootFolder.

Returns:

Node – The single fully resolved local Node.

Raises:

OpcUaError – Translation fails, is ambiguous, or leaves unresolved or out-of-server targets.

objects#

The standard ObjectsFolder, without a server read.

Type:

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 | RelativePath | str])

    Nodes belonging to this client or browse paths starting at RootFolder.

  • attribute (AttributeId | int | str | 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 | RelativePath | str])

    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)

    Requested publishing interval in milliseconds. Values at or below zero request the fastest supported publishing interval. The server request uses whole milliseconds.

  • attribute (AttributeId | int | str | None)

    Group attribute, default Value.

  • lifetime_count (int)

    Requested subscription lifetime count, default 60.

  • max_keep_alive_count (int)

    Requested keep-alive count, default 20.

  • max_notifications_per_publish (int)

    Zero means no requested limit.

  • priority (int)

    Native unsigned byte priority, default zero.

  • publishing_enabled (bool)

    Enable native publishing, default True.

  • sampling_interval_ms (float)

    Milliseconds. Negative values (default -1) inherit the publishing interval. Zero requests the fastest practical sampling.

  • queue_size (int)

    Native monitored-item queue request, default zero.

  • discard_oldest (bool)

    Native monitored-item discard policy, default False.

  • poll_interval_ms (float | 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 – A value, Node group, or resolved duplicate is invalid.

  • TypeError – A keyword or iterable element has an unsupported type.

  • OverflowError – An integer is outside the range of its subscription setting.

  • ExceptionGroup – Monitored-item rejections in request order, each carrying the Node identifier and original status. Setup is rolled back first.

  • OpcUaError – A native setup service fails. Cleanup cannot hide this error.

types#

The standard TypesFolder, without a server read.

Type:

Node

views#

The standard ViewsFolder, without a server read.

Type:

Node