Skip to main content

BTEng OPC UA

bteng-opcua

OPC UA integration for the BTEng Behavior Tree engine, for behavior-tree-based communication and control in industrial automation.

  • 12 async OPC UA leaf nodes for connections, reads and writes, subscriptions, history access, and method calls, plus a generic Sleep helper
  • Registry generated from the server's information model with bteng-opcua harvest, so addresses and data types are not written by hand
  • Trees run from the command line with bteng-opcua run, with no Python to write

All OPC UA nodes implement the StatefulActionNode protocol: they return RUNNING while an async operation is in flight, then SUCCESS or FAILURE on completion.

Requirements

  • Python 3.12+
  • bteng >= 0.3.2
  • asyncua >= 1.0.0
  • PyYAML >= 6.0

Installation

bteng-opcua is not on PyPI yet, so install it from GitHub:

pip install git+https://github.com/BTEng-dev/bteng-opcua.git

Quick start

Describe what to harvest. This is the only file you write by hand:

# harvest.yaml
server: opc.tcp://192.168.1.10:4840     # or: nodeset: models/robot.NodeSet2.xml
harvest:
  - "Objects/Robot"                     # every Variable and Method underneath

Generate the registry, then run a tree against it:

bteng-opcua harvest -s harvest.yaml -o nodes.yaml           # generate; commit nodes.yaml
bteng-opcua harvest -s harvest.yaml -o nodes.yaml --check   # CI: fail if the model drifted
bteng-opcua run tree.xml -n nodes.yaml                      # run a tree

Generation is a build step: trees run offline against the committed YAML, and the server is contacted only when you regenerate. Aliases default to the snake_cased BrowseName (MoveToPosition becomes move_to_position).

A tree addresses nodes by alias, so no node IDs or data types appear in the XML:

<BTEng format_version="1.0" main_tree_to_execute="main">
  <Tree ID="main">
    <Sequence name="root">
      <OpcUaConnect name="connect" endpoint="opc.tcp://localhost:4840" session_id="main"/>
      <OpcUaRead name="read_temp" session_id="main" node_alias="temperature"
                 value="{current_temp}"/>
      <OpcUaDisconnect name="disconnect" session_id="main"/>
    </Sequence>
  </Tree>

  <!-- Required for value="{key}" to WRITE to the blackboard. -->
  <TreeNodesModel>
    <Action ID="OpcUaRead"><output_port name="value"/></Action>
  </TreeNodesModel>
</BTEng>

Declare output ports in <TreeNodesModel>. Without it the parser treats every {key} attribute as an input, and OpcUaRead silently falls back to storing under its alias.

Nodes

Node Purpose
OpcUaConnect Establish a named OPC UA session
OpcUaDisconnect Close a session (best-effort)
OpcUaReconnect Re-establish a dropped session using its saved config
OpcUaRead Read one variable node to the blackboard
OpcUaWrite Write one variable node from the blackboard
OpcUaBatchRead Read multiple nodes in a single round-trip
OpcUaBatchWrite Write multiple nodes in parallel
OpcUaCallMethod Invoke an OPC UA method with typed input/output args
OpcUaSubscribe React to data-change notifications (on_change or on_value mode)
OpcUaWaitForValue Poll a node until its value matches an expected value
OpcUaReadHistory Read a time-windowed history from a HistoricalAccess node
OpcUaCondition Read a node and check it against an expected value

Nodes resolve addresses through a registry alias (node_alias, recommended) or directly with a raw node_id and node_index.

Try it

Run everything against the bundled demo server:

python examples/demo_server.py                                   # terminal 1
bteng-opcua harvest -s examples/config/harvest.yaml -o examples/config/nodes.yaml
bteng-opcua run examples/trees/ -n examples/config/nodes.yaml

See examples/README.md for the project layout.

Documentation

  • Authoring guide: full walkthrough from harvest spec to running tree
  • Reference: harvest authentication, registry format, data types, sessions, and Python/XML integration
  • Changelog

Development

pip install -e ".[dev]"
pytest tests/

tests/test_subscribe_integration.py needs a real OPC UA server.

License

MIT

Metadata

Release files for bteng-opcua 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bteng-opcua 0.2.2
File Size Uploaded Provenance Actions
bteng_opcua-0.2.2.tar.gz 63.5 kB Without provenance Details for bteng_opcua-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bteng-opcua 0.2.2
File Interpreter ABI Platform Actions
bteng_opcua-0.2.2-py3-none-any.whl Python 3 none any Details for bteng_opcua-0.2.2-py3-none-any.whl

Total release size: 118.6 kB

Release files / bteng_opcua-0.2.2.tar.gz

Download URL bteng_opcua-0.2.2.tar.gz
Size 63.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a9cf4d5bae4cac45ad2ced6b156241d5587278fcb0e5b37f268ae939ef55f135
BLAKE2b-256 checksum
How to use checksums
3dad3ed44fa66611c76a7a4788a29edd17501dcc659e32a7806a8697dca4208a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / bteng_opcua-0.2.2-py3-none-any.whl

Download URL bteng_opcua-0.2.2-py3-none-any.whl
Size 55.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc6872bfcdbfb7adddc9731adb02a2b931fd46daf9bd437423a4ba04b5c1ae26
BLAKE2b-256 checksum
How to use checksums
f20b87c35781d2276e506da42ea3a4dc6525d5764987f9314a9ca012a7a13397
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for bteng-opcua 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page