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 attemps to expose as much functionality as possible but if you want more flexibility it is possible and adviced to use 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

close_secure_channel()[source]
close_session()[source]

Close session

connect()[source]

High level method Connect, create and activate session

connect_and_find_servers()[source]

Connect, ask server for a list of known servers, and disconnect

connect_and_find_servers_on_network()[source]

Connect, ask server for a list of known servers on network, and disconnect

connect_and_get_server_endpoints()[source]

Connect, ask server for endpoints, and disconnect

connect_socket()[source]

connect to socket defined in url

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.

delete_nodes(nodes, recursive=False)[source]
disconnect()[source]

High level method Close session, secure channel and socket

disconnect_socket()[source]
export_xml(nodes, path)[source]

Export defined nodes to xml

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

find_servers_on_network()[source]
get_endpoints()[source]
get_namespace_array()[source]
get_namespace_index(uri)[source]
get_node(nodeid)[source]

Get node using NodeId object or a string representing a NodeId

get_objects_node()[source]
get_root_node()[source]
get_server_node()[source]
import_xml(path=None, xmlstring=None)[source]

Import nodes defined in xml

load_client_certificate(path)[source]

load our certificate from file, either pem or der

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

open_secure_channel(renew=False)[source]

Open secure channel, if renew is True, renew channel

register_namespace(uri)[source]

Register a new namespace. Nodes should in custom namespace, not 0. This method is mainly implemented for symetry with server

send_hello()[source]

Send OPC-UA hello to server

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 files

Call this before connect()

set_user(username)[source]

Set user name for the connection. initial user from the URL will be overwritten

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

activate_session(parameters)[source]
add_nodes(nodestoadd)[source]
add_references(refs)[source]
browse(parameters)[source]
browse_next(parameters)[source]
call(methodstocall)[source]
close_secure_channel()[source]

close secure channel. It seems to trigger a shutdown of socket in most servers, so be prepare to reconnect

close_session(deletesubscriptions)[source]
connect_socket(host, port)[source]

connect to server socket and start receiving thread

create_monitored_items(params)[source]
create_session(parameters)[source]
create_subscription(params, callback)[source]
delete_monitored_items(params)[source]
delete_nodes(params)[source]
delete_references(refs)[source]
delete_subscriptions(subscriptionids)[source]
disconnect_socket()[source]
find_servers(params)[source]
find_servers_on_network(params)[source]
get_endpoints(params)[source]
history_read(params)[source]
modify_monitored_items(params)[source]
open_secure_channel(params)[source]
publish(acks=None)[source]
read(parameters)[source]
register_server(registered_server)[source]
register_server2(params)[source]
send_hello(url, max_messagesize=0, max_chunkcount=0)[source]
set_security(policy)[source]
translate_browsepaths_to_nodeids(browsepaths)[source]
write(params)[source]