Skip to main content

Pure Python OPC-UA client and server library

Project description

Pure Python OPC-UA Client and Server

API is similar to the python bindings of freeopcua c++ client and servers, but small changes due different implementation and to make it more pythonic.

Most code is autogenerated from xml specification using same code as the one that is going to be used for freeopcua C++ client and server. Adding more functionnality shoud be trivial since most code is autogenerated

with Python3 the server and client do not require any third party libraries. If using python2.7 you need to install enum34, with pip for example. Server and client can be run with pypy.


Client: what works:
* connection to server, opening channel, session
* browsing and reading attributes value
* gettings nodes by path and nodeids
* creating subscriptions
* subscribing to items for data change

Client: what is not implemented yet
* method call
* adding/removing nodes
* subscribing to events
* subscribing to status change
* adding all modify methods
* certificate handling
* user and password

in addition testing against more servers should be done


Server: what works:
* creating channel and sessions
* read/set attributes and browse
* tested client: freeopcua C++ , freeopcua Python, uaexpert

Server: what is not implemented
* security (users, certificates, etc)
* subscriptions
* methods

Example client code:

```
import logging
from opcua import Client
from opcua import uaprotocol as ua

class SubHandler(object):
def data_change(self, handle, node, val, attr):
print("Python: New data change event", handle, node, val, attr)

def event(self, handle, event):
print("Python: New event", handle, event)

if __name__ == "__main__":
logging.basicConfig(level=logging.WARN)
client = Client("opc.tcp://localhost:4841/freeopcua/server/")
client.connect()

#getting root folder and browsing
root = client.get_root_node()
print(root.get_children())

#getting a variable by path and setting its value attribute
myvar = root.get_child(["0:Objects", "2:NewObject", "2:MyVariable"])
var.set_value(ua.Variant([23], ua.VariantType.Int64))

#subscribing to data change event to our variable
handler = SubHandler()
sub = client.create_subscription(500, handler)
sub.subscribe_data_change(myvar)

time.sleep(100)

client.disconnect()
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

freeopcua-0.6.1.tar.gz (195.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page