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. However there are differences due to a 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.
with Python3 the server and client do not require any third party libraries. If using python2.7 or pypy 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
* adding nodes
Client: what is not implemented yet
* method call
* 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
* gettings nodes by path and nodeids
* autogenerate addres space from spec
* adding nodes to address space
* tested client: freeopcua C++ , freeopcua Python, uaexpert
Server: what is not implemented
* security (users, certificates, etc)
* subscriptions
* methods
* removing nodes
Example client code:
```
from opcua import ua, Client
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__":
client = Client("opc.tcp://localhost:4841/freeopcua/server/")
client.connect()
root = client.get_root_node()
#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()
```
Example server code:
```
from opcua import ua, Server
server = Server()
server.set_endpoint("opc.tcp://localhost:4841/freeopcua/server/")
server.set_server_name("FreeOpcUa Example Server")
server.start()
objects = server.get_objects_node()
myfolder = objects.add_folder(2, "myfolder")
myvar = myfolder.add_variable(2, "myvar", 6.7)
```
API is similar to the python bindings of freeopcua c++ client and servers. However there are differences due to a 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.
with Python3 the server and client do not require any third party libraries. If using python2.7 or pypy 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
* adding nodes
Client: what is not implemented yet
* method call
* 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
* gettings nodes by path and nodeids
* autogenerate addres space from spec
* adding nodes to address space
* tested client: freeopcua C++ , freeopcua Python, uaexpert
Server: what is not implemented
* security (users, certificates, etc)
* subscriptions
* methods
* removing nodes
Example client code:
```
from opcua import ua, Client
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__":
client = Client("opc.tcp://localhost:4841/freeopcua/server/")
client.connect()
root = client.get_root_node()
#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()
```
Example server code:
```
from opcua import ua, Server
server = Server()
server.set_endpoint("opc.tcp://localhost:4841/freeopcua/server/")
server.set_server_name("FreeOpcUa Example Server")
server.start()
objects = server.get_objects_node()
myfolder = objects.add_folder(2, "myfolder")
myvar = myfolder.add_variable(2, "myvar", 6.7)
```
Project details
Release history Release notifications | RSS feed
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.2.tar.gz
(195.2 kB
view hashes)