Metadata-Version: 2.4
Name: excalidraw-render
Version: 0.1.2
Summary: Clean, deterministic, browser-free renderer for .excalidraw files (PNG/SVG).
Project-URL: Homepage, https://github.com/shivama205/excalidraw-render
Project-URL: Source, https://github.com/shivama205/excalidraw-render
Project-URL: Issues, https://github.com/shivama205/excalidraw-render/issues
Author: Shivam Mathur
License: MIT License
        
        Copyright (c) 2026 Shivam Mathur
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: diagram,excalidraw,png,renderer,svg
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Requires-Dist: cairosvg>=2.7
Requires-Dist: pillow>=10.0
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-cov>=5; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Description-Content-Type: text/markdown

# excalidraw-render

[![CI](https://github.com/shivama205/excalidraw-render/actions/workflows/ci.yml/badge.svg)](https://github.com/shivama205/excalidraw-render/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/excalidraw-render.svg)](https://pypi.org/project/excalidraw-render/)
[![Python](https://img.shields.io/pypi/pyversions/excalidraw-render.svg)](https://pypi.org/project/excalidraw-render/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Clean, deterministic, browser-free renderer for `.excalidraw` files. Pure Python + cairosvg. No Node, no headless browser, no `node-canvas`.

![hero](docs/hero.png)

```bash
pip install excalidraw-render

excalidraw-render diagram.excalidraw                    # → diagram.png
excalidraw-render diagram.excalidraw -f svg             # → diagram.svg
excalidraw-render diagram.excalidraw --width 1200       # PNG at 1200px wide
excalidraw-render ./docs/                               # batch: every .excalidraw → .png
```

## Why this exists

The Excalidraw ecosystem's existing exporters either need Node + `node-canvas` ([`excalidraw_export`](https://www.npmjs.com/package/excalidraw_export)) or a headless browser running React ([`@excalidraw/excalidraw`](https://www.npmjs.com/package/@excalidraw/excalidraw)). Both are heavy, fragile in CI, and slow to start.

`excalidraw-render` is Python + cairosvg. Single-digit-megabyte install, instant startup, no native canvas libs, no Chromium. Useful for:

- **Static-site generators** (Hugo, MkDocs, Sphinx) baking `.excalidraw` to PNG at build time
- **CI/screenshot pipelines** where pulling Chromium is overkill
- **Doc + slide generators** that want predictable, deterministic vector output
- **Terminal viewers** (Kitty, iTerm2, Sixel) — coming in v0.2

## Trade-off: no hand-drawn style

Excalidraw's signature squiggly look comes from [`roughjs`](https://roughjs.com/), a JavaScript library with no native Python port. `excalidraw-render` produces **clean vector output** instead. This is a deliberate trade-off — clean output is what most doc / slide / report pipelines actually want, and skipping roughjs removes the heaviest dependency.

A pure-Python roughjs port (`pyroughjs`) is on the v0.2 roadmap. Until then, if you need the hand-drawn look, use Excalidraw's official export.

## Comparison

| | `excalidraw-render` | [`excalidraw_export`](https://www.npmjs.com/package/excalidraw_export) | [`@excalidraw/excalidraw`](https://www.npmjs.com/package/@excalidraw/excalidraw) |
|---|---|---|---|
| Language | Python | Node | React + Node |
| Hand-drawn (roughjs) | No (v0.2 stretch) | Yes | Yes |
| PNG output | Yes | via `rsvg-convert` | Yes |
| SVG output | Yes | Yes | Yes |
| PDF output | v0.2 | via `rsvg-convert` | No |
| Headless browser needed | No | No | Yes |
| Native canvas / image libs | No | Yes (`node-canvas`) | No |
| Install size | ~10 MB | ~150 MB | Depends |
| Batch / watch mode | Batch ✓ / watch v0.2 | No | No |
| Terminal protocols | v0.2 (iTerm / Kitty / Sixel) | No | No |

## Install

```bash
pip install excalidraw-render
```

On Linux you may need `libcairo2`:
```bash
sudo apt-get install libcairo2          # Debian / Ubuntu
sudo dnf install cairo                  # Fedora
sudo pacman -S cairo                    # Arch
```

On macOS, Cairo is typically already present via Homebrew. If not:
```bash
brew install cairo
```

## Usage

### CLI

```bash
# Single file → PNG next to source
excalidraw-render diagram.excalidraw

# Specify output + format
excalidraw-render diagram.excalidraw -o /tmp/out.svg -f svg

# Higher resolution PNG
excalidraw-render diagram.excalidraw --width 1600

# Or scale instead of fixed width
excalidraw-render diagram.excalidraw --scale 2.0

# Transparent background
excalidraw-render diagram.excalidraw --no-background

# Batch mode: every .excalidraw in a directory
excalidraw-render ./docs/diagrams/ -o ./public/diagrams/
```

### Python API

```python
from excalidraw_render.render import load_scene, render_svg, render_png

scene = load_scene("diagram.excalidraw")

# SVG as a string
svg = render_svg(scene)

# PNG to a file
render_png(scene, "diagram.png", width=1200)

# PNG to a binary stream
import io
buf = io.BytesIO()
render_png(scene, buf, scale=2.0)
```

## What's supported in v0.1

**Elements:** rectangle, ellipse, diamond, arrow, line, text, freedraw, image, frame.
**Arrowheads:** `arrow`, `triangle`, `triangle_outline`, `bar`, `dot`, `diamond`, `diamond_outline`, `crowfoot_one`, `crowfoot_many`, `crowfoot_one_or_many`.
**Styling:** stroke color/width, fill color, stroke style (solid/dashed/dotted), opacity, per-element rotation.
**Text:** multi-line, text-align (left/center/right), vertical-align (top/middle/bottom), Excalidraw font families mapped to web-safe fonts.
**Freedraw:** smooth path via Catmull-Rom → cubic Bezier conversion.
**Image:** embedded raster data from the scene's `files` dict.
**Frame:** dashed boundary box with optional label.

Coverage matrix: [`docs/elements.md`](docs/elements.md).

## What's not supported yet

Documented in [`CHANGELOG.md`](CHANGELOG.md). Highlights:

- Roughness / hand-drawn look (v0.2 — needs roughjs port)
- PDF / JPEG output (v0.2)
- Hachure / cross-hatch / zigzag / dots fill patterns (currently fall back to solid)
- Container-bound text positioning fidelity (padding-aware layout)
- Terminal output (iTerm / Kitty / Sixel) — v0.2
- Markdown preprocessor subcommand — v0.2
- Watch mode — v0.2

## Contributing

This is pre-alpha and breaking changes between minor versions are likely until v1.0. Issues, ideas, and PRs welcome — please file at https://github.com/shivama205/excalidraw-render/issues.

Local dev:
```bash
git clone https://github.com/shivama205/excalidraw-render
cd excalidraw-render
python -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/pytest
.venv/bin/ruff check src tests
.venv/bin/mypy src
```

## License

MIT — see [LICENSE](LICENSE).
