Python bindings for Web4 trust-native infrastructure
Project description
Web4-Core Python Bindings
Python bindings for the Web4 trust-native infrastructure core library, implemented in Rust via PyO3.
Installation
From source (requires Rust and maturin)
pip install maturin
cd web4-core/python
maturin develop
Building a wheel
maturin build --release
pip install target/wheels/*.whl
Usage
import web4_core
# 1. Create an LCT (in-memory primitive)
lct, keypair = web4_core.PyLct.new(web4_core.PyEntityType.Human, None)
# 2. Anchor to a ledger — LCTs are blockchain tokens, must be minted
ledger = web4_core.PyInMemoryLedger()
receipt = ledger.mint(lct)
print(f"Minted at index {receipt.entry_index}, hash {receipt.entry_hash[:16]}...")
# 3. Sign and verify
message = b"Hello, Web4!"
signature = keypair.sign(message)
assert lct.verify_signature(message, signature)
# 4. Generate proof of existence
proof = ledger.anchor(lct.id)
assert ledger.verify_proof(proof)
# 5. Trust tensor — 3 root dimensions, fractally extensible
trust = web4_core.PyT3()
trust.observe(web4_core.PyTrustDimension.Talent, 0.9)
trust.observe(web4_core.PyTrustDimension.Training, 0.85)
trust.observe(web4_core.PyTrustDimension.Temperament, 0.88)
print(f"Aggregate trust: {trust.aggregate():.3f}")
# Fractal sub-dimension observation
trust.observe_sub_dimension("rust_proficiency", web4_core.PyTrustDimension.Training, 0.92)
# 6. Value tensor — same pattern
value = web4_core.PyV3()
value.observe(web4_core.PyValueDimension.Valuation, 0.9)
value.observe(web4_core.PyValueDimension.Veracity, 0.85)
value.observe(web4_core.PyValueDimension.Validity, 0.88)
# 7. Identity coherence (C × S × Φ × R)
coherence = web4_core.PyCoherence.with_values(0.8, 0.8, 0.7, 0.9)
print(f"Total coherence: {coherence.total():.3f}")
print(f"Limiting factor: {coherence.limiting_factor()}")
For persistence, swap PyInMemoryLedger for PyLocalLedger:
ledger = web4_core.PyLocalLedger.open("./team-ledger.jsonl")
lct, _ = web4_core.PyLct.new(web4_core.PyEntityType.AiSoftware, None)
receipt = ledger.mint(lct)
# Reopen later — state is replayed from the file with chain-integrity checks
ledger = web4_core.PyLocalLedger.open("./team-ledger.jsonl")
restored = ledger.lookup(lct.id)
assert restored is not None
Worked example: durable host identity
The snippet above shows the primitives. The repo ships a small,
self-contained script that turns them into a one-command setup for a
host's persistent presence — keypair on disk (chmod 600), local
hash-chained ledger, public LCT sidecar, and an idempotent re-run that
verifies the chain instead of regenerating:
# Generate identity (or verify, if it already exists)
python examples/identity_bootstrap.py --name laptop-01
# Read-only attestation check
python examples/identity_bootstrap.py --name laptop-01 --verify
Source: python/examples/identity_bootstrap.py.
Copy and adapt — change the entity type, point at a different base
directory, layer hardware-binding (TPM / secure enclave) on top, etc.
Ledger backends
| Backend | Use case |
|---|---|
PyInMemoryLedger |
Tests, prototyping, ephemeral runs |
PyLocalLedger |
Solo dev, team-scoped accountability, regulated/air-gapped environments — persistent, hash-chained, tamper-evident |
| ACT chain backend (separate package, future) | Federation-wide consensus via Cosmos SDK gateway |
API Reference
Entity Types
PyEntityType.Human— Human userPyEntityType.AiSoftware— Software-bound AI agentPyEntityType.AiEmbodied— Hardware-bound AI agentPyEntityType.Organization— OrganizationPyEntityType.Role— Role (first-class entity)PyEntityType.Task— TaskPyEntityType.Resource— ResourcePyEntityType.Hybrid— Hybrid entity
Trust Tensor (T3) — 3 Root Dimensions
T3 is fractally multidimensional. The three root dimensions below are each themselves open-ended RDF sub-graphs of context-specific sub-dimensions, linked via web4:subDimensionOf.
PyTrustDimension.Talent— Natural aptitude and capability for a specific rolePyTrustDimension.Training— Acquired expertise, certifications, and experiencePyTrustDimension.Temperament— Behavioral consistency, reliability, ethical disposition
Use observe(dimension, score) to record a root-level observation, or observe_sub_dimension(name, parent, score) to record a sub-dimension under one of the roots.
Value Tensor (V3) — 3 Root Dimensions
Same fractal structure as T3.
PyValueDimension.Valuation— Worth ascribed to the contributionPyValueDimension.Veracity— Truthfulness and reliability of the claimPyValueDimension.Validity— Soundness and applicability in context
Identity Coherence (C × S × Φ × R)
C(Continuity) — Temporal consistencyS(Stability) — Resistance to perturbationΦ(Phi) — Information integrationR(Reachability) — Network connection
Coherence is multiplicative: a low score in any factor limits the whole. Use limiting_factor() to identify the bottleneck.
Crypto
PyKeyPair.generate()— Generate a fresh Ed25519 keypairPyKeyPair.from_secret_bytes(bytes)— Reconstruct from 32-byte secretkeypair.sign(message)— Sign bytes (returns 64-byte signature)lct.verify_signature(message, signature)— Verify against the LCT's public keyweb4_core.sha256(data)/sha256_hex(data)— SHA-256 helpers
Patent Notice
This software implements technology covered by US Patents 11,477,027 and 12,278,913, and pending application 19/178,619. See PATENTS.md for the patent grant terms.
License
AGPL-3.0-or-later. See LICENSE.
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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file web4_core-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: web4_core-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 532.4 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42938ae38179c6e771cff474a14d2d6b608ef237c9c6bf95b20dc86f2519c83a
|
|
| MD5 |
acabd4cc511843078047269b59ae2a7b
|
|
| BLAKE2b-256 |
13a9773242c2ea37e8aa831451535c1dcd6439bf96e2535c881d753a93dfc1aa
|