Skip to main content

Generate DrawIO shape libraries from SVGs

Project description

SVG2DrawIOLib

PyPI - Version PyPI - Python Version CI Publish to PyPI codecov License: MIT Code style: ruff

Convert SVG files into DrawIO/diagrams.net shape libraries with support for colorable icons.


Features

Easy Conversion: Transform SVG files into DrawIO libraries with a single command 🎨 Color Editing: Optional CSS injection for color customization in DrawIO 📏 Customizable: Configure icon dimensions, namespaces, and more 🚀 Modern CLI: Beautiful, colorful output with rich-click 🔒 Type Safe: Full type annotations with mypy

Quick Start

Installation

pip install SVG2DrawIOLib

Basic Usage

# Convert individual SVG files to DrawIO library
SVG2DrawIOLib create icon1.svg icon2.svg -o my-library.xml

# Convert all SVGs in a directory
SVG2DrawIOLib create icons/ -o my-library.xml

# Convert all SVGs in directory and subdirectories
SVG2DrawIOLib create icons/ -o my-library.xml --recursive

# Enable color editing in DrawIO
SVG2DrawIOLib create icons/ --css -o colorable-icons.xml

# Custom dimensions with proportional scaling
SVG2DrawIOLib create icons/ --max-size 64 -o large-icons.xml -R

Documentation

Commands

Create a Library

Create a new DrawIO library from SVG files:

# Basic usage
SVG2DrawIOLib create icon1.svg icon2.svg -o my-library.xml

# From directory
SVG2DrawIOLib create icons/ -o my-library.xml

# Recursive directory scan
SVG2DrawIOLib create icons/ -o my-library.xml --recursive

Add Icons to Library

Add new icons to an existing library:

# Add single icon
SVG2DrawIOLib add my-library.xml new-icon.svg

# Add multiple icons
SVG2DrawIOLib add my-library.xml icon1.svg icon2.svg

# Replace duplicates
SVG2DrawIOLib add my-library.xml icon.svg --replace

Remove Icons

Remove icons from a library by name:

SVG2DrawIOLib remove my-library.xml icon-name1 icon-name2

List Icons

List all icons in a library:

SVG2DrawIOLib list my-library.xml

Advanced Features

Color Editing

Enable color customization in DrawIO by injecting CSS classes:

SVG2DrawIOLib create icons/ --css -o colorable-icons.xml

This allows users to change icon colors directly in DrawIO's interface.

Proportional Scaling

Scale icons proportionally while maintaining aspect ratio:

# Scale so longest side is 64px
SVG2DrawIOLib create icons/ --max-size 64 -o large-icons.xml

Fixed Dimensions

Set exact dimensions for all icons:

SVG2DrawIOLib create icons/ --width 50 --height 50 -o square-icons.xml

Custom Configuration

# Custom XML namespace
SVG2DrawIOLib create icons/ --namespace "http://custom.ns" -o library.xml

# Custom CSS tag for color editing
SVG2DrawIOLib create icons/ --css --tag "circle" -o library.xml

# Custom CSS color
SVG2DrawIOLib create icons/ --css --css-color "#FF0000" -o library.xml

How It Works

SVG2DrawIOLib converts SVG files into DrawIO's custom library format:

  1. Parses SVG files and extracts dimensions
  2. Optionally injects CSS classes for color editing support
  3. Encodes SVG as data URI with base64 encoding
  4. Wraps in mxGraphModel XML structure
  5. Compresses using zlib deflate algorithm
  6. Generates library JSON/XML compatible with DrawIO

For technical details about the conversion process, see ARCHITECTURE.md.

Python API

Use SVG2DrawIOLib programmatically:

from pathlib import Path
from SVG2DrawIOLib import SVGProcessor, LibraryManager, SVGProcessingOptions

# Configure processing options
options = SVGProcessingOptions(add_css=True, css_color="#000000")

# Process SVG file
processor = SVGProcessor(options)
icon = processor.process_svg_file(Path("icon.svg"), max_dimension=64)

# Create library
manager = LibraryManager()
metadata = manager.create_library([icon], Path("library.xml"))

print(f"Created library with {metadata.icon_count} icons")

For complete API documentation, see ARCHITECTURE.md.

License

SVG2DrawIOLib is distributed under the terms of the MIT license.

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

svg2drawiolib-1.0.0.tar.gz (77.6 kB view details)

Uploaded Source

Built Distribution

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

svg2drawiolib-1.0.0-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file svg2drawiolib-1.0.0.tar.gz.

File metadata

  • Download URL: svg2drawiolib-1.0.0.tar.gz
  • Upload date:
  • Size: 77.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for svg2drawiolib-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b85cc2fd3e9d231ac3a59668a0a579c506f5d67395ec6a199e5698a7764cd131
MD5 87feede3137f8612fdbe0114ab91064f
BLAKE2b-256 4e649e1fa5244a8e2a4cf262ba75c6313920a3590ee64a88b21c9bd451f448e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for svg2drawiolib-1.0.0.tar.gz:

Publisher: publish.yml on jamesbconner/SVG2DrawIOLib

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

File details

Details for the file svg2drawiolib-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: svg2drawiolib-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for svg2drawiolib-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1d0316a96949aabad1e7845cb2b4d56ca1a0315aa8b534e50a35d4b24383f97
MD5 c2d4f902bcd7ad486ed9e9f092b0c8b4
BLAKE2b-256 74c542cb0caed6894c876e2e5549811179187f9d3d2e3429e85cf19839faf6c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for svg2drawiolib-1.0.0-py3-none-any.whl:

Publisher: publish.yml on jamesbconner/SVG2DrawIOLib

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