Skip to main content

Scrybe Mermaid — standalone PNG iTXt codec (Rust-backed)

Project description

scrybe-mermaid

Standalone PNG iTXt codec: embeds and extracts Mermaid diagram source as invisible metadata inside a PNG file. Python on the outside, Rust on the inside.

What it does

Uses the PNG iTXt (international text) metadata chunk mechanism to store Mermaid diagram source alongside the rendered image. The PNG is fully valid and renders normally in any image viewer. The source text travels with the image and can be round-tripped without loss.

Python quick start

pip install scrybe-mermaid
from pathlib import Path
from scrybe_mermaid import embed, extract

source = """
graph TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
"""

# diagram.png: any PNG — render one with mmdc, Kroki, or the Mermaid live editor
png_in = Path("diagram.png").read_bytes()
png_out = embed(png_in, source)
Path("diagram-with-source.png").write_bytes(png_out)

payload = extract(png_out)  # verifies the embedded sha256 — raises ValueError if tampered
if payload.source != source:  # optional
    raise ValueError("Round-trip mismatch")
print(f"Round-tripped {len(payload.source)} chars; sha256={payload.sha256[:12]}…")

The resulting PNG renders normally in any image viewer and carries its own Mermaid source for round-tripping. See the API reference below.

Codec format

  • Chunk key: scrybe-mermaid
  • Value: JSON { "source": "<mermaid source>", "sha256": "<hex>", "uuid": "<v4>" }

The sha256 field is a SHA-256 digest of the source bytes, and extract enforces it by default: the digest is recomputed from the extracted source and compared against the stored value. Three outcomes are distinguished:

Outcome Python Rust
Digest present and matching payload with verified == True Ok(VerifiedPayload) with VerificationStatus::Verified
Digest present but mismatched (tampered) raises ValueError Err(MermaidError::VerificationFailed { expected, actual, .. })
No digest stored (older/foreign payload) payload with verified == False, sha256 == "" Ok(VerifiedPayload) with VerificationStatus::NoDigest

A payload with no digest is never reported as verified. For forensics on tampered or foreign payloads, extract_unverified returns the raw stored fields without any check.

Role in the architecture

scrybe-mermaid is a self-contained utility crate with no dependency on scrybe-core. It is used by scrybe-mcp-server (the embed/extract tools), scrybe-cli (scrybe mermaid embed/extract/verify), and the Tauri backend.

Key public types and entry points

Symbol Description
embed(png_bytes, source) -> Result<Vec<u8>> Inserts iTXt chunk; returns modified PNG bytes
extract(png_bytes) -> Result<VerifiedPayload> Reads the iTXt chunk and verifies the stored sha256 against the source; mismatch → MermaidError::VerificationFailed
extract_unverified(png_bytes) -> Result<MermaidPayload> Raw stored fields, no digest check (forensics)
VerifiedPayload source: String + uuid: String + verification: VerificationStatus
VerificationStatus Verified { algorithm, digest } or NoDigest (older/foreign payloads)
MermaidPayload Raw stored source + sha256 + uuid (unchecked)
MermaidError Error type covering missing chunk, malformed JSON, PNG decode failure, digest mismatch (VerificationFailed { expected, actual, .. })

Build and test

cargo build -p scrybe-mermaid
cargo test -p scrybe-mermaid

The codec parses PNG chunks from first principles — no external binaries required.

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

scrybe_mermaid-0.6.1.tar.gz (56.2 kB view details)

Uploaded Source

Built Distributions

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

scrybe_mermaid-0.6.1-cp39-abi3-win_amd64.whl (199.8 kB view details)

Uploaded CPython 3.9+Windows x86-64

scrybe_mermaid-0.6.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (349.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

scrybe_mermaid-0.6.1-cp39-abi3-macosx_11_0_arm64.whl (308.1 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file scrybe_mermaid-0.6.1.tar.gz.

File metadata

  • Download URL: scrybe_mermaid-0.6.1.tar.gz
  • Upload date:
  • Size: 56.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for scrybe_mermaid-0.6.1.tar.gz
Algorithm Hash digest
SHA256 531332310e718728acd862e38b2432963436fe61e2f7a791a732ac395e7b25dc
MD5 d3a9fd3bddb550f541e70109090ea02f
BLAKE2b-256 4271b391cacf97397d8e6233476481f599b8f9cd70af0eaacff39c1409b9b090

See more details on using hashes here.

Provenance

The following attestation bundles were made for scrybe_mermaid-0.6.1.tar.gz:

Publisher: release.yml on hartsock/scrybe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file scrybe_mermaid-0.6.1-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for scrybe_mermaid-0.6.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 14471a717f2af3f169797e6019ec9af973984c704565b0954ea69407e58e7dc9
MD5 347eee1e42a3e2350d6ba9cd0bf60cdb
BLAKE2b-256 aafaffaa89c5fba974a5b5d2c93eb361146438a11b95fa98f07bdf426583f7ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for scrybe_mermaid-0.6.1-cp39-abi3-win_amd64.whl:

Publisher: release.yml on hartsock/scrybe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file scrybe_mermaid-0.6.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scrybe_mermaid-0.6.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e7d0dbb1af594531632c686e3695ccca2e1c8b80a7ea75f4798db23abb03e5e1
MD5 b472c83bd0bd74de159423296b8c32e0
BLAKE2b-256 b14708c7ee2c611b6056480b09e0937246eb69e722b6caa7f2e0fb4ea06327f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for scrybe_mermaid-0.6.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on hartsock/scrybe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file scrybe_mermaid-0.6.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scrybe_mermaid-0.6.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eb73c850ad5bee3642f2204a74c7ec85954da17fc54f90aa58d5e2e3bab173b9
MD5 4349ccc83ae6d7b7ef406adaca814080
BLAKE2b-256 c123f07a15b2f972c6161de3d3da266370709f933ab992d1f4aa9050a28f7358

See more details on using hashes here.

Provenance

The following attestation bundles were made for scrybe_mermaid-0.6.1-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on hartsock/scrybe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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