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)
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>" }

The sha256 field is a SHA-256 digest of the source bytes for lightweight integrity verification.

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<MermaidPayload> Reads and parses the iTXt chunk
MermaidPayload source: String + sha256: String
MermaidError Error type covering missing chunk, malformed JSON, PNG decode failure

Build and test

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

Depends on the png crate for chunk-level PNG manipulation and base64 for encoding the iTXt payload. 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.5.0.tar.gz (51.8 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.5.0-cp39-abi3-win_amd64.whl (196.7 kB view details)

Uploaded CPython 3.9+Windows x86-64

scrybe_mermaid-0.5.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (346.3 kB view details)

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

scrybe_mermaid-0.5.0-cp39-abi3-macosx_11_0_arm64.whl (304.9 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for scrybe_mermaid-0.5.0.tar.gz
Algorithm Hash digest
SHA256 5075f80ad2784a69d9fda48e2237bdedd4efb279418bfe682aaa04b5e3876756
MD5 77a309c6092bb4322d36c89d63c75f89
BLAKE2b-256 598b2602ebf594c5846d5275c3f34b682c46a4d38c02454f90a1660ac4ac6b8d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scrybe_mermaid-0.5.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f5470ea496e92559cac4d324a5f7f5a2700624f491c673c61832796da80d2f89
MD5 d1872f65b294cf61b20eef3748b8fad4
BLAKE2b-256 0a80534489252126b3ce6f2051636eb45ef4909095a389291a86df3dabc2e368

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scrybe_mermaid-0.5.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 109c63a3bc8548ef2abb90458c7e7453423f0f3e79d3e592e50393a7a0dce55c
MD5 c1a70ab7520acbbd4ab41e91f49b6464
BLAKE2b-256 ff5be07c30f8f315bc93a621d1f00670f3181dad9f9d3ad76707beb89e4d80f3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scrybe_mermaid-0.5.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 01f6586465a5d9501dc9dfcc7fd09791116deb9d60a5439c9af7fb7b3d8dc233
MD5 797271af0f8f8b4d77cc646ef085ed14
BLAKE2b-256 9d6518545f63f025d209fee60926092b717821c6bba52f7d24de4219701aff80

See more details on using hashes here.

Provenance

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