Skip to main content

kapps_semantic_middleware

Let a piece of Python running on or beside a shopfloor resource expose what it can do through an RDF knowledge graph — and let other instances discover and invoke that capability through the graph, rather than through hardcoded network addresses.

A resource's state is described in the graph as a protocol-interface parameter. The middleware wires that description to the real device: it discovers peers, serves them over REST, and keeps the graph and the device in step.

pip install kapps-semantic-middleware

Python 3.12 or newer. Nothing else is required to use the library.

Run the examples

The scenarios and the factory demo need a few more packages and a running GraphDB. One extra covers the packages:

pip install "kapps-semantic-middleware[examples]"

Run kapps-examples to copy the runnable files out of the installed package into a directory you own — a notebook inside site-packages cannot be opened, edited or re-run. The path is relative to your current working directory:

kapps-examples ./kapps-examples
cd kapps-examples

You now have scenario 1 and scenario 2 (each as a .py and a .ipynb), the seed data they load, and a docker/ directory. Add the [notebooks] extra if you want to open the .ipynb files in Jupyter; the .py versions run with [examples] alone.

Start a GraphDB

Docker is needed for the examples and the demo, never for the library itself.

cd docker
docker compose up -d

GraphDB comes up on http://localhost:7200 and the kapps-demo repository is created for you. This works the same on Linux, macOS and Windows.

Then point the library at it:

Linux and macOS:

export GRAPHDB_URL=http://localhost:7200
export GRAPHDB_USERNAME=admin
export GRAPHDB_PASSWORD=root

PowerShell (current session only):

$env:GRAPHDB_URL = "http://localhost:7200"
$env:GRAPHDB_USERNAME = "admin"
$env:GRAPHDB_PASSWORD = "root"

cmd.exe (current session only):

set GRAPHDB_URL=http://localhost:7200
set GRAPHDB_USERNAME=admin
set GRAPHDB_PASSWORD=root

To persist across sessions on Windows, use setx instead of set. setx does not affect the shell that runs it — open a new shell after running it.

Three variables, not four. GraphDBCredentials.from_env() in kapps_triplestore_interface also reads GRAPHDB_REPOSITORY, and your own code may well use it — but nothing here does. The examples and the demo name kapps-demo in code, and the test suite names its own. A GRAPHDB_REPOSITORY you already have set is ignored rather than obeyed, because these are the parts that wipe and re-seed whatever they connect to.

Never point GRAPHDB_URL at a GraphDB you care about. The examples and the demo clear the repository they use on every run. docker compose down -v wipes the throwaway one; the next run re-seeds it.

Run a scenario

python scenario1_hello_world.py     # operation coordination through the graph
python scenario2_door.py            # direct state discovery and control

Run the factory demo

A small factory as six real processes — one per mock PLC, one per middleware instance, and a controller that discovers every unit in the graph and drives it over REST. You watch it from a browser.

kapps-transferunit-factory

It serves a live status page on http://127.0.0.1:8080/. --units N sets how many TransferUnits run (two by default); --force clears the graph even when a live factory still holds a fresh heartbeat. Ctrl+C stops every process.

Where to read what

AGENTS.md Start here to build against this. The consumption rules — including the ones that fail silently — and which name to import from where.
docs/mechanics/ How each mechanism actually works, one page each, in construction order.
CONTEXT-MAP.md The five contexts and how they relate.
examples/ Scenario 1 and scenario 2, self-contained.
demo/transferunits/ The factory demo.

If you are writing code against this library, read AGENTS.md first. Several of its rules are constraints that do not appear in any type signature and fail by producing quietly wrong behaviour rather than an exception.

Questions

Can I install it with uv? Yes. Run this instead of the pip install at the top, not after it:

uv add "kapps-semantic-middleware[examples]"

pip install answers externally-managed-environment. Debian and Ubuntu mark their system Python as externally managed, so pip refuses to write into it. Use a virtual environment:

python3 -m venv .venv
. .venv/bin/activate
pip install "kapps-semantic-middleware[examples]"

uv needs no such step — it creates and manages the environment itself.

Is [examples] really needed for the factory? Yes, and leaving it out does not look like an error. uvicorn and rdflib reach you anyway, as dependencies of something else; amqtt — the in-process MQTT broker each unit brings up — does not. Without it the launcher seeds the graph, the first middleware starts and prints its address, and then the mock PLC repeats a line like

broker at 127.0.0.1:18831 not ready yet ([Errno 111] Connection refused), retrying in 5.0s

for as long as you let it run. No traceback appears, and neither does Factory running. If you see that line, the extra is what is missing.

Status

Usable, and still on a 0.x line: the scenarios and the factory demo run end to end, but the API may still move, and a minor bump may break you. CHANGELOG.md records what each release changed.

Contributing

Development happens in a private repository and this one is the published half: it carries one commit per release and no ancestry, so there is nothing here to branch from.

Bug reports and questions are welcome as issues on this repository. A patch is welcome too -- say what it changes and why, and it will be applied on the development side and credited in CHANGELOG.md for the release that carries it.

Acknowledgements

This package is developed as part of the INF subproject of the CRC 1574: Circular Factory for the Perpetual Product. This work is therefore supported by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) [grant-number: SFB-1574-471687386].

Metadata

Release files for kapps-semantic-middleware 0.2.0

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

Source distribution (sdist)

Source distribution for kapps-semantic-middleware 0.2.0
File Size Uploaded
kapps_semantic_middleware-0.2.0.tar.gz 804.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kapps-semantic-middleware 0.2.0
File Interpreter ABI Platform
kapps_semantic_middleware-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / kapps_semantic_middleware-0.2.0.tar.gz

Download URL kapps_semantic_middleware-0.2.0.tar.gz
Size 804.3 kB
Tags Source
SHA-256 checksum
How to use checksums
94a4640f1f1387218a5c36f48c769bd02f430b2b1382ba2cf7e5f2a4ba10fc99
BLAKE2b-256 checksum
How to use checksums
a4077f3fcbe6f645a1c4e4a8cb3ee23fa1d44e3d3b8cfb09996bdb63d236fcd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / kapps_semantic_middleware-0.2.0-py3-none-any.whl

Download URL kapps_semantic_middleware-0.2.0-py3-none-any.whl
Size 366.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e050d5d1ad90a5871a3277f25bf299cfab80f23fbd9ab63e9545a31bf28252f4
BLAKE2b-256 checksum
How to use checksums
a122e61c7fb2f233db817f93ab173c2472f21acaa50a8ab6d23a2c818094b1b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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