Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

foodblock-0.1.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

foodblock-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

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

Hashes for foodblock-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7c97977c70e026024425adb87980c29e764de0f3815bb1e161e7aea7e616c8b8
MD5 10ff6609b375ea0fc2a3d001c34c0c17
BLAKE2b-256 71716dad9988547ebcf2b9492687508bd63c7730134520cf9be6ba887966355d

See more details on using hashes here.

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

Hashes for foodblock-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d91c69839a8cf4831feaef06a7074d4bb9947ef962cb39a2980953b8ade573b6
MD5 50e694922641012a0445044efbd2f2d8
BLAKE2b-256 1838cd9ed5a85f41820572f935c35c9addfa9f974e1aae2d8561cf6f5d2216c8

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