Skip to main content

Typed deterministic Mermaid diagrams and local rendering for Modwire.

Project description

modwire-mermaid

Build Mermaid diagrams from typed, immutable Python objects. modwire-mermaid validates a diagram's structure and compiles it to deterministic Mermaid text behind one class-based API. It performs no filesystem, browser, CLI, or image-rendering work.

Compilation is package-native. It does not depend on Node.js or mermaid-py; consumers may pass the generated source to their preferred Mermaid renderer or validation binary.

What is Mermaid?

Mermaid is a text-based diagramming language. A short definition such as:

flowchart LR
    contract[Typed Python contract] --> compiler[modwire-mermaid]
    compiler --> source[Mermaid source]
    source --> renderer[Mermaid renderer]

can be rendered as a diagram by Mermaid-aware tools. Because the source is plain text, diagrams are easy to review in version control, generate in tests, embed in Markdown, and render independently in a browser or CI pipeline.

This package owns the first two steps: typed Python contracts and Mermaid source generation. Mermaid itself—or a service or application that embeds it—owns visual rendering.

Installation

modwire-mermaid requires Python 3.12 or newer.

pip install modwire-mermaid

Quick start

Create a diagram with one of the feature builders, then compile it with the standard façade:

from modwire_mermaid import ModwireMermaidFactory
from modwire_mermaid.timeline.diagram import ModwireTimelineBuilder

diagram = (
    ModwireTimelineBuilder.create("Release history")
    .section("2026")
    .period("Q1", "Private beta")
    .period("Q2", "Public release", "Documentation")
    .build()
)

source = ModwireMermaidFactory.standard().compile(diagram)
print(source)

The result is plain Mermaid source:

---
config:
  timeline:
    disableMulticolor: false
---
timeline LR
  title Release history
  section 2026
    Q1 : Private beta
    Q2 : Public release : Documentation

Put the result inside a fenced mermaid block in supported Markdown, send it to the Mermaid Live Editor, or pass it to the renderer used by your application. Rendering is deliberately outside this package, so server-side code can generate diagrams without shipping a browser or Node.js runtime.

Public API

The supported root imports below are generated from modwire_mermaid.__all__.

Symbol Purpose Primary API
ModwireDiagramError Report an invalid diagram contract or unsupported diagram operation.
ModwireMermaid Compile validated Modwire diagram contracts into deterministic Mermaid source. compile(diagram: modwire_mermaid.contracts.ModwireBaseDiagram) -> str
ModwireMermaidFactory Build the standard Mermaid façade with every bundled diagram compiler. standard() -> modwire_mermaid.facade.ModwireMermaid
__version__ Installed distribution version.

Executable example

Source: compile_timeline.py. This file is executed by the test suite.

from modwire_mermaid import ModwireMermaidFactory
from modwire_mermaid.timeline.diagram import ModwireTimelineBuilder

diagram = (
    ModwireTimelineBuilder.create("Release history")
    .section("2026")
    .period("Q1", "Private beta")
    .period("Q2", "Public release", "Documentation")
    .build()
)

source = ModwireMermaidFactory.standard().compile(diagram)

Diagrams

All contracts inherit ModwireBaseDiagram. It enforces required children, unique child identities, and valid references consistently. Empty strings and tuples explicitly represent Mermaid features that are absent; public contracts are non-nullable and have no implicit defaults.

Design guarantees and scope

  • Typed, frozen Pydantic contracts reject invalid diagram structure before compilation.
  • Identical contracts produce identical Mermaid text, making snapshot tests and source diffs stable.
  • The standard factory supports every diagram type listed above through one compile() method.
  • The package generates text only; it does not render SVG/PNG, invoke Mermaid CLI, or write files.
  • Mermaid parser and renderer compatibility must be checked by the consuming application.

Development and release

Run uv sync --all-groups and make verify. Releases use strict SemVer tags and PyPI Trusted Publishing configured for repository 9orky/modwire-mermaid, workflow release.yml, and environment pypi. Create and push the tag before publishing its GitHub Release; that release drives the shared build, attaches the verified distributions, and then publishes the same files to PyPI.

git tag -a v1.0.1 -m "v1.0.1"
git push origin v1.0.1
gh release create v1.0.1 --verify-tag --generate-notes --title v1.0.1

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

modwire_mermaid-1.0.1.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

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

modwire_mermaid-1.0.1-py3-none-any.whl (42.8 kB view details)

Uploaded Python 3

File details

Details for the file modwire_mermaid-1.0.1.tar.gz.

File metadata

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

File hashes

Hashes for modwire_mermaid-1.0.1.tar.gz
Algorithm Hash digest
SHA256 40536d85414150a73f5cf935ad2ba10eeed074c1826e708e8aadb16eeaec4cfb
MD5 2f74760d313d269592ab0018c485339d
BLAKE2b-256 cd9a499218753365c0159eaadf41337c7c9e8dfa226a03b0050b5fa511f54080

See more details on using hashes here.

Provenance

The following attestation bundles were made for modwire_mermaid-1.0.1.tar.gz:

Publisher: release.yml on 9orky/modwire-mermaid

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

File details

Details for the file modwire_mermaid-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: modwire_mermaid-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 42.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for modwire_mermaid-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf76bb9b3fb363d0b39af287b1a04baa53545fea1217dcf5da6fb274c3d288ab
MD5 50980714f2199a8d92d329c1454089cb
BLAKE2b-256 0689aa42b1c20c3c22899d7ab08b817a7958dc13f759cf473a2728c988e9b6ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for modwire_mermaid-1.0.1-py3-none-any.whl:

Publisher: release.yml on 9orky/modwire-mermaid

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