Skip to main content

The standalone Link/Chain homoiconic composition primitives (UCO) — pure stdlib, zero deps.

Project description

universal-chain-ontology (UCO)

The standalone Link / Chain homoiconic composition primitives — the chain substrate that a lot of systems reimplement. Pure stdlib, zero dependencies.

from uco import Link, Chain, LinkResult, LinkStatus

class Inc(Link):
    async def execute(self, context=None, **_):
        ctx = dict(context or {}); ctx["n"] = ctx.get("n", 0) + 1
        return LinkResult(status=LinkStatus.SUCCESS, context=ctx)

# a Chain IS a Link (homoiconic) — so Chains nest like any other Link
import asyncio
out = asyncio.run(Chain("two", [Inc(), Inc()]).execute({"n": 0}))
assert out.context["n"] == 2

What's here

primitive what it is
Link ABC: execute(context) -> LinkResult
Chain sequential composition of Links; a Chain IS a Link
EvalChain a Chain + an evaluator loop (gate to a condition / max_cycles)
Compiler a Chain whose output is itself a Link
ConfigLink / LinkConfig config-driven Links
LinkResult / LinkStatus the result + status enum (SUCCESS/BLOCKED/ERROR/AWAITING_INPUT)

Why standalone

The same Link/Chain abstraction was living inside SDNA and getting copy-pasted into other projects. UCO is that abstraction extracted once. Downstreams import uco; sdna.chain_ontology re-exports it, so existing from sdna.chain_ontology import Link, Chain, … keeps working unchanged and the class identity is shared (one Link everywhere).

MIT.

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

universal_chain_ontology-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

universal_chain_ontology-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file universal_chain_ontology-0.1.0.tar.gz.

File metadata

File hashes

Hashes for universal_chain_ontology-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e0b19e33ffa26fbd2dc0911e8e656ff3407b55ea2f32245969b19eddf2943367
MD5 a355bd3d8378c54eb731484a4f4130bb
BLAKE2b-256 1b79598cc51771a11462b126a9f42e8846bb459df74aa0de670adbf0b8c999de

See more details on using hashes here.

File details

Details for the file universal_chain_ontology-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for universal_chain_ontology-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 231b3d5f6326c1bf568958d55f4ce850aa85928dfdf1c3f69b8942d85ac10b91
MD5 dd82edd3547372b33d5ea1e67b5b6e24
BLAKE2b-256 b5c01df4443b1cc4e7acf44e3a2635d5bd37f4c8bcaba06b32657f48827ee3dc

See more details on using hashes here.

Supported by

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