Skip to main content

pykzee

Pykzee is an engine that allows plug-ins to operate on a JSON-like state tree. Each plug-in can publish its internal state as part of the global state tree, and can subscribe to changes of any part of the tree. Plug-ins can also send commands between each other.

The original purpose of Pykzee is to build home automations systems, but it may well be useful in other contexts.

Installation

$ pip install pykzee

Pykzee depends on pyimmutable, which will automatically be installed by pip if it is not present. Installation of pyimmutable may require a C++17 compiler on the host system.

Example Use

mkdir pykzee-config
cd pykzee-config
pykzee

The pykzee executable will run forever. Because it is run in an empty directory, the internal state is empty ({}), and since no plug-ins are loaded, nothing will ever change the state. Press CTRL-C to stop the pykzee process. Then try this:

echo '{"__plugin__": "core-plugin"}' >core.json
mkdir plugins
echo '{"__plugin__": "pykzee.core.StateLoggerPlugin", "pretty": true}' >plugins/StateLogger.json
pykzee

Launching pykzee again now yields some output on the terminal. What you see is the StateLoggerPlugin printing the complete state tree. It will do this again every time the state changes.

Pykzee instantiates a plug-in wherever it finds an object with a __plugin__ key in the original state tree. The value of the __plugin__ key must be a Python class (in dotted notation like foo.bar.baz.classname, referring to the class classname in the module foo.bar.baz) or the special value core-plugin. The object containing the __plugin__ key will get replaced in the state tree with the state published by the plug-in. The original object may have keys other than __plugin__, and those can be used to configure the plug-in, see for example the pretty key in this example, which make the StateLoggerPlugin output the state in pretty printed form.

While the pykzee process is still active in your terminal, open another terminal window, enter the same pykzee-config directory and add another file:

echo '{"hello": "world"}' >test.json

The pykzee process will notice the change in the configuration file directory and reload the configuration. Go back to your first terminal window, and you will see that the StateLoggerPlugin has printed the new state tree, which now includes a field named test with the contents {"hello": "world"}.

Plug-ins Distributed with the Core Package

The pykzee package comes with three plug-ins included:

  • core-plugin: publishes information about the Pykzee engine itself, e.g. which plug-ins are loaded.

  • pykzee.core.StateLoggerPlugin: logs the complete state tree on every change.

  • pykzee.core.CodePlugin: executes a snippet of Python code with access to the state tree.

Further Reading

Pykzee only becomes useful once further plug-ins are installed. Please have a look at the pykzee-inspector plug-in, which contains a web server that serves a browser application for inspecting the Pykzee state.

Metadata

Release files for pykzee 0.1.1

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

Source distribution (sdist)

Source distribution for pykzee 0.1.1
File Size Uploaded
pykzee-0.1.1.tar.gz 14.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pykzee 0.1.1
File Interpreter ABI Platform
pykzee-0.1.1-py3.7.egg Legacy Egg format - - Details
pykzee-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 116.2 kB

Release files / pykzee-0.1.1.tar.gz

Download URL pykzee-0.1.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1a58a110ab8163052c3c9d98557f558327d37c726e23daf9ba4c5f51f3f41fbb
BLAKE2b-256 checksum
How to use checksums
35ec9c1aef437c711a58e72175174e4c53398cb078aae32309fcdc263ed8fe77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3

Release files / pykzee-0.1.1-py3.7.egg

Download URL pykzee-0.1.1-py3.7.egg
Size 72.4 kB
Tags Egg
SHA-256 checksum
How to use checksums
a0353c2ab2935e9a108cd4bd4c1c0a1efbaa70398be949bb07ba48624fb91452
BLAKE2b-256 checksum
How to use checksums
200ca33987679f42cec5648f3ebc74975c62160e9b823a3418ff0f16bb337382
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3

Release files / pykzee-0.1.1-py3-none-any.whl

Download URL pykzee-0.1.1-py3-none-any.whl
Size 29.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c7e8c0b6302042fb3b0b8e663f10a07094a3812b9934e4382f0e125775bf388
BLAKE2b-256 checksum
How to use checksums
37f363fc0e459e7eadd7cf816e7c05baa3596277c2816263f5b3ad10acceb4e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

3 release files

0.1.0

3 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