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.2.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.2-cp39-abi3-win_amd64.whl (199.8 kB view details)

Uploaded CPython 3.9+Windows x86-64

scrybe_mermaid-0.6.2-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.2-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.2.tar.gz.

File metadata

  • Download URL: scrybe_mermaid-0.6.2.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.2.tar.gz
Algorithm Hash digest
SHA256 20b9170aae79351e2d576f0b41251bfaa2274a7fad77f16b46557ce58fda93bf
MD5 9eb113440311aba42d3686c1205a726c
BLAKE2b-256 187ae8ec8c940b8a1536279ae66b128c72d26c0eab5318426efa0f3cc1a87da5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scrybe_mermaid-0.6.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e698ff23076f1d801f7daf01f4d4946087e6afb691b0f4f824a446adafd73ed8
MD5 cc3b008d479e80f20bf1b73c58c7b60f
BLAKE2b-256 b35e54933a5ee2f539badaa2f444421e1691ab03d187ef8098ebd8acce8ac24c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scrybe_mermaid-0.6.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f5f7988d1cb666f3ff807490288770b1e99e570b4d0749cf083bf1ae2ec6b578
MD5 56c5f016bfd2de7ef45c1dfb20cb6a83
BLAKE2b-256 c5c7eb4c87b7f715922b820271e69ef90dc59981ea664d167ce356c598f1e715

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scrybe_mermaid-0.6.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c95b7df8bf08ba232e36ac1faa272b07938d54d5a8b20ac0672e312c58f7a386
MD5 4df2a424997cc3aca970edf2678c5ecc
BLAKE2b-256 39795e85d0e23812195d3c82258f2601706353774383fdd14bedbd46708380be

See more details on using hashes here.

Provenance

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