OPC-UA Client Class¶
-
class
opcua.client.client.
Client
(url, timeout=4)[source]¶ High level client to connect to an OPC-UA server.
This class makes it easy to connect and browse address space. It attempts to expose as much functionality as possible but if you want more flexibility it is possible and advised to use the UaClient object, available as self.uaclient, which offers the raw OPC-UA services interface.
-
activate_session
(username=None, password=None, certificate=None)[source]¶ Activate session using either username and password or private_key
-
connect_and_find_servers_on_network
()[source]¶ Connect, ask server for a list of known servers on network, and disconnect
-
create_session
()[source]¶ send a CreateSessionRequest to server with reasonable parameters. If you want o modify settings look at code of this methods and make your own
-
create_subscription
(period, handler)[source]¶ Create a subscription. returns a Subscription object which allow to subscribe to events or data on server handler argument is a class with data_change and/or event methods. period argument is either a publishing interval in milliseconds or a CreateSubscriptionParameters instance. The second option should be used, if the opcua-server has problems with the default options. These methods will be called when notfication from server are received. See example-client.py. Do not do expensive/slow or network operation from these methods since they are called directly from receiving thread. This is a design choice, start another thread if you need to do such a thing.
-
static
find_endpoint
(endpoints, security_mode, policy_uri)[source]¶ Find endpoint with required security mode and policy URI
-
find_servers
(uris=None)[source]¶ send a FindServer request to the server. The answer should be a list of servers the server knows about A list of uris can be provided, only server having matching uris will be returned
-
load_enums
()[source]¶ generate Python enums for custom enums on server. This enums will be available in ua module
-
load_private_key
(path)[source]¶ Load user private key. This is used for authenticating using certificate
-
load_type_definitions
(nodes=None)[source]¶ Load custom types (custom structures/extension objects) definition from server Generate Python classes for custom structures/extension objects defined in server These classes will available in ua module
-
register_namespace
(uri)[source]¶ Register a new namespace. Nodes should in custom namespace, not 0. This method is mainly implemented for symetry with server
-
register_nodes
(nodes)[source]¶ Register nodes for faster read and write access (if supported by server) Rmw: This call modifies the nodeid of the nodes, the original nodeid is available as node.basenodeid
-
server_policy_id
(token_type, default)[source]¶ Find PolicyId of server’s UserTokenPolicy by token_type. Return default if there’s no matching UserTokenPolicy.
-
server_policy_uri
(token_type)[source]¶ Find SecurityPolicyUri of server’s UserTokenPolicy by token_type. If SecurityPolicyUri is empty, use default SecurityPolicyUri of the endpoint
-
set_password
(pwd)[source]¶ Set user password for the connection. initial password from the URL will be overwritten
-
set_security
(policy, certificate_path, private_key_path, server_certificate_path=None, mode=<MessageSecurityMode.SignAndEncrypt: 3>)[source]¶ Set SecureConnection mode. Call this before connect()
-
set_security_string
(string)[source]¶ Set SecureConnection mode. String format: Policy,Mode,certificate,private_key[,server_private_key] where Policy is Basic128Rsa15, Basic256 or Basic256Sha256,
Mode is Sign or SignAndEncrypt certificate, private_key and server_private_key are
paths to .pem or .der filesCall this before connect()
-
-
class
opcua.client.ua_client.
UaClient
(timeout=1)[source]¶ low level OPC-UA client.
It implements (almost) all methods defined in opcua spec taking in argument the structures defined in opcua spec.
In this Python implementation most of the structures are defined in uaprotocol_auto.py and uaprotocol_hand.py available under opcua.ua
-
close_secure_channel
()[source]¶ close secure channel. It seems to trigger a shutdown of socket in most servers, so be prepare to reconnect
-