Skip to content

o6.server.Server

High-level OPC UA Server.

Parameters

port : int, optional TCP port number (default 4840). logger : logging.Logger, optional Custom logger object. loop : asyncio.AbstractEventLoop, optional Event loop used for cooperative scheduling. When provided (or when a running loop is detected), the server avoids spawning a background thread and instead schedules non-blocking iterations on the loop. If None and no running loop exists, a daemon thread is used as a fallback. certificate : str, Path, or bytes, optional Server certificate (file path or raw bytes). private_key : str, Path, or bytes, optional Server private key (file path or raw bytes). trust_list : list, optional Trusted certificates for client verification. issuer_list : list, optional Issuer certificates. revocation_list : list, optional Certificate revocation lists. secure_only : bool If True, reject unencrypted connections (default False). accept_all_certificates : bool If True, trust all client certificates (default False). application_uri : str, optional Override the default application URI.

Example

server = Server(port=4840) with server: ... temp = server.add_variable("Temperature", ... server.objects_node, 22.5) ... print(temp.value) 22.5

o6.server.Server

Bases: Server

High-level OPC UA Server.

Parameters

port : int, optional TCP port number (default 4840). logger : logging.Logger, optional Custom logger object. loop : asyncio.AbstractEventLoop, optional Event loop used for cooperative scheduling. When provided (or when a running loop is detected), the server avoids spawning a background thread and instead schedules non-blocking iterations on the loop. If None and no running loop exists, a daemon thread is used as a fallback. certificate : str, Path, or bytes, optional Server certificate (file path or raw bytes). private_key : str, Path, or bytes, optional Server private key (file path or raw bytes). trust_list : list, optional Trusted certificates for client verification. issuer_list : list, optional Issuer certificates. revocation_list : list, optional Certificate revocation lists. secure_only : bool If True, reject unencrypted connections (default False). accept_all_certificates : bool If True, trust all client certificates (default False). application_uri : str, optional Override the default application URI.

Example

server = Server(port=4840) with server: ... temp = server.add_variable("Temperature", ... server.objects_node, 22.5) ... print(temp.value) 22.5

Attributes

objects_node property

objects_node

The Objects folder (i=85).

types_node property

types_node

The Types folder (i=86).

server_node property

server_node

The Server object (i=2253).

Functions

start

start()

Start the server networking layer.

The asyncio event loop handles all I/O, timers, and callbacks. When no running loop is detected (synchronous callers), a lightweight background daemon thread drives the loop instead.

stop

stop()

Shut down the server.

read_attribute

read_attribute(nodeid, attr_id)

Read any standard attribute by its integer AttributeId.

read_object_property

read_object_property(object_id, property_name)

Read an object property by BrowseName.

add_reverse_connect

add_reverse_connect(url, callback=None)

Register a reverse connect to a client listening at url.

The server will periodically attempt to establish a connection to the given client endpoint (e.g. opc.tcp://localhost:4841).

Parameters

url : str The OPC UA endpoint URL of the listening client. callback : callable, optional Called with (handle, state) on every state change.

Returns

int A handle that can be passed to :meth:remove_reverse_connect.

write_object_property

write_object_property(object_id, property_name, value)

Write an object property by BrowseName.

remove_reverse_connect

remove_reverse_connect(handle)

Remove a reverse connect registration.

Parameters

handle : int The handle returned by :meth:add_reverse_connect.

add_variable

add_variable(
    name,
    parent,
    value=None,
    *,
    nodeid=None,
    data_type=None,
    writable=True,
    historizing=False,
    ns=1
)

Add a variable node to the address space.

Parameters

name : str or LocalizedText Browse name (and display name) of the variable. parent : NodeIdLike Parent node (typically server.objects_node). value : any, optional Initial value. The OPC UA data-type is inferred automatically unless data_type is given explicitly. nodeid : NodeIdLike, optional Requested node id. None -> server assigns one. data_type : NodeIdLike, optional Explicit data type. If None, inferred from value. writable : bool Whether the variable is writable by clients (default True). historizing : bool Whether the variable supports historical data access (default False). ns : int Namespace index for the browse name (default 1).

Returns

VariableNode

add_object

add_object(
    name,
    parent,
    *,
    nodeid=None,
    type_definition=BASE_OBJECT_TYPE,
    ns=1
)

Add an object node to the address space.

Parameters

name : str or LocalizedText Browse name / display name. parent : NodeIdLike Parent node. nodeid : NodeIdLike, optional Requested node id. type_definition : NodeIdLike, optional Type definition node (default: BaseObjectType i=58). ns : int Namespace index for the browse name.

Returns

ObjectNode

add_object_type

add_object_type(
    name, parent=BASE_OBJECT_TYPE, *, nodeid=None, ns=1
)

Add an object type node.

Parameters

name : str or LocalizedText Browse name / display name. parent : NodeIdLike, optional Parent type node (default: BaseObjectType i=58). nodeid : NodeIdLike, optional Requested node id. ns : int Namespace index for the browse name.

Returns

ObjectTypeNode

add_variable_type

add_variable_type(
    name,
    parent=BASE_VARIABLE_TYPE,
    *,
    data_type=NS0_DT_DOUBLE,
    value_rank=-1,
    nodeid=None,
    ns=1
)

Add a variable type node.

Parameters

name : str or LocalizedText Browse name / display name. parent : NodeIdLike, optional Parent type (default: BaseVariableType i=62). data_type : NodeIdLike, optional Data type (default: Double i=11). value_rank : int Value rank (default: -1 = scalar). nodeid : NodeIdLike, optional Requested node id. ns : int Namespace index for the browse name.

Returns

VariableTypeNode

add_method

add_method(
    name,
    parent,
    callback,
    *,
    input_args=None,
    output_args=None,
    nodeid=None,
    ns=1
)

Add a method node to the address space.

Parameters

name : str or LocalizedText Browse name / display name. parent : NodeIdLike Parent node (typically an object node). callback : callable Python function called when a client invokes the method. Signature: callback(*inputs) -> list[output_values] input_args : list of Argument, optional Input argument descriptors. output_args : list of Argument, optional Output argument descriptors. nodeid : NodeId, optional Requested node id. ns : int Namespace index for the browse name.

Returns

MethodNode

add_reference

add_reference(
    source, target, reference_type, *, forward=True
)

Add a reference between two nodes.

delete_node

delete_node(nodeid, *, delete_references=True)

Delete a node from the address space.

call

call(object_id, method_id, input_args=[])

Call a method node server-side with admin privileges.

Matches client.call() — returns (StatusCode, *output_arguments).

Parameters

object_id : NodeIdLike The object node that owns the method. method_id : NodeIdLike The method node to invoke. input_args : list, optional Input argument values.

Returns

tuple (status_code, output1, output2, ...)

read

read(target, attr=o6.AttributeId.VALUE)

Read one or more node attributes from the server.

write

write(target, value, attr=o6.AttributeId.VALUE)

Write one or more node attributes on the server.

If value is a :class:DataValue, it is written directly via UA_Server_writeDataValue — preserving any explicit status code and timestamps stored in the object. Otherwise behaves as before.

browse_node

browse_node(nodeid, result_mask)

Browse children of a node.

translate_browse_paths

translate_browse_paths(request)

Server-side translate browse paths to node ids.

read_node_info

read_node_info(nodeid)

Return (node_class_int, browse_name) for a node.

find_data_type

find_data_type(nodeid)

Look up a DataType by NodeId and return the Python type or metadata.

add_namespace

add_namespace(uri)

Register a namespace URI in the client's local namespace table and return its assigned index.

If ns.append() is used to load pre-built companion specs, all ns.append() calls must come before any manual add_namespace() calls. Pre-built Namespaces expect specific canonical indices; a manual add_namespace() beforehand would occupy a slot and cause ns.append() to raise ValueError.

Calling add_namespace() after all ns.append() calls is safe and simply appends at the next free index.

.. note:: End users should never need to call this directly — all namespace registration goes through client.ns.append().