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.3.tar.gz (56.1 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.3-cp39-abi3-win_amd64.whl (199.8 kB view details)

Uploaded CPython 3.9+Windows x86-64

scrybe_mermaid-0.6.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (349.1 kB view details)

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

scrybe_mermaid-0.6.3-cp39-abi3-macosx_11_0_arm64.whl (308.0 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: scrybe_mermaid-0.6.3.tar.gz
  • Upload date:
  • Size: 56.1 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.3.tar.gz
Algorithm Hash digest
SHA256 bd59022621331e0b9a1ead7be0b4bac14a347d7966b15689cb430a0ea6b964ba
MD5 f567d3b123ecff381252d904bd038d1e
BLAKE2b-256 3e9f1f60d974fe8b81cc5be2cf23403e1e3733d1b2e697529105125a5942eabb

See more details on using hashes here.

Provenance

The following attestation bundles were made for scrybe_mermaid-0.6.3.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.3-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for scrybe_mermaid-0.6.3-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4306e92f21f51a1cb719269b11e876af0a25bbd13879993b6854cbeb0579dac9
MD5 0ee669d56106585210154e522db8e44a
BLAKE2b-256 730e39ad309c5bc56f724d0830745c5a5be0ff742c4477bb8f012938b36f8b70

See more details on using hashes here.

Provenance

The following attestation bundles were made for scrybe_mermaid-0.6.3-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.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scrybe_mermaid-0.6.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fcb672bd2e3ee275c3fe84dca6b6bb86b2510a13dbee72191951506ec9725849
MD5 4563ad8c8830b7beb7311be3ade8328e
BLAKE2b-256 081b5cd10d10079033c7a3cef98910d634a0a9d44a27836fb0c40928fe28e84b

See more details on using hashes here.

Provenance

The following attestation bundles were made for scrybe_mermaid-0.6.3-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.3-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scrybe_mermaid-0.6.3-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 28f08f83b6a0fc9c631563e496b8dbf2a9241a67aabdb3db507e1fc6a5ae4e9d
MD5 648e626df3638f35298cfb6a3518602d
BLAKE2b-256 41c9407bb54e3294f30f963071162183590a078fd9c6e8c5f339240c3aff1865

See more details on using hashes here.

Provenance

The following attestation bundles were made for scrybe_mermaid-0.6.3-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