SDK for the FoodBlock protocol — a content-addressable primitive for universal food data
Project description
foodblock
SDK for the FoodBlock Protocol — a content-addressable data primitive for universal food data.
Install
pip install foodblock
Quick Start
from foodblock import create, update, chain
# Create a block
farm = create('actor.producer', {'name': 'Green Acres Farm'})
# => {'hash': 'a1b2c3...', 'type': 'actor.producer', 'state': {...}, 'refs': {}}
# Create with references
bread = create('substance.product', {'name': 'Sourdough', 'price': 4.50}, {
'seller': farm['hash']
})
# Update a block (creates a new block referencing the previous)
updated = update(bread['hash'], 'substance.product', {'name': 'Sourdough', 'price': 5.00})
# updated['refs']['updates'] == bread['hash']
Base Types
FoodBlock defines 6 base types. Subtypes use dot notation (e.g. actor.producer).
| Type | Description |
|---|---|
actor |
People, orgs, devices, agents |
place |
Locations, facilities, appliances |
substance |
Ingredients, products, materials |
transform |
Processes that change substances |
transfer |
Movement of substances between actors |
observe |
Reviews, scans, certifications |
API
create(type_, state=None, refs=None)
Create a new FoodBlock. Returns {'hash', 'type', 'state', 'refs'}.
update(previous_hash, type_, state=None, refs=None)
Create an update block that supersedes a previous block.
compute_hash(type_, state=None, refs=None)
Compute the SHA-256 hash without creating a full block object.
canonical(type_, state, refs)
Produce the deterministic canonical JSON string used for hashing.
chain(start_hash, resolve, max_depth=100)
Follow the updates chain backwards. resolve is async (hash) -> block or None.
tree(start_hash, resolve, max_depth=20)
Follow ALL refs recursively to build the full provenance tree.
generate_keypair()
Generate an Ed25519 keypair. Returns {'public_key', 'private_key'} as hex strings.
sign(block, author_hash, private_key_hex)
Sign a block. Returns {'foodblock', 'author_hash', 'signature'}.
verify(wrapper, public_key_hex)
Verify a signed block wrapper. Returns True or False.
Cross-Language Compatibility
The Python and JavaScript SDKs produce identical hashes for the same input. This is verified by shared test vectors.
Sandbox
Try the live sandbox at api.foodx.world/foodblock
License
MIT
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 Distribution
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 foodblock-0.1.0.tar.gz.
File metadata
- Download URL: foodblock-0.1.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c97977c70e026024425adb87980c29e764de0f3815bb1e161e7aea7e616c8b8
|
|
| MD5 |
10ff6609b375ea0fc2a3d001c34c0c17
|
|
| BLAKE2b-256 |
71716dad9988547ebcf2b9492687508bd63c7730134520cf9be6ba887966355d
|
File details
Details for the file foodblock-0.1.0-py3-none-any.whl.
File metadata
- Download URL: foodblock-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d91c69839a8cf4831feaef06a7074d4bb9947ef962cb39a2980953b8ade573b6
|
|
| MD5 |
50e694922641012a0445044efbd2f2d8
|
|
| BLAKE2b-256 |
1838cd9ed5a85f41820572f935c35c9addfa9f974e1aae2d8561cf6f5d2216c8
|