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¶
Functions¶
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.
read_attribute ¶
Read any standard attribute by its integer AttributeId.
read_object_property ¶
Read an object property by BrowseName.
add_reverse_connect ¶
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 an object property by BrowseName.
remove_reverse_connect ¶
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 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_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 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 a reference between two nodes.
call ¶
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, ...)
write ¶
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.
translate_browse_paths ¶
Server-side translate browse paths to node ids.
find_data_type ¶
Look up a DataType by NodeId and return the Python type or metadata.
add_namespace ¶
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().