Python Quick Start
Install
Section titled “Install”pip install edgesvgPython 3.9+. Pre-built wheels for macOS (arm64, x64), Linux (x64, arm64), and Windows (x64).
Basic Usage
Section titled “Basic Usage”Vectorize an image
Section titled “Vectorize an image”import edgesvg
# Auto mode — EdgeSVG picks the best strategy for the imageresult = edgesvg.vectorize("logo.png", method="auto")
# The result contains svg, report, and metadataprint(result["svg"][:200]) # SVG stringprint(result["requested_method"]) # what you asked forprint(result["effective_method"]) # what was actually usedprint(result["decision"]) # whyInspect quality metrics
Section titled “Inspect quality metrics”metrics = result["report"]["metrics"]print(f"SSIM: {metrics['ssim']:.4f}")print(f"Edge F1: {metrics['edge_f1']:.4f}")print(f"Foreground: {metrics['foreground_iou']:.4f}")print(f"Path count: {metrics['path_count']}")print(f"File size: {metrics['file_size']} bytes")Analyze an image before converting
Section titled “Analyze an image before converting”# Get a recommendation and image classificationinfo = edgesvg.inspect("logo.png")print(info["recommendation"]) # "logo", "icon", "illustration", "photo"
# Get raw image featuresanalysis = edgesvg.analyze("logo.png")print(analysis["analysis"]["kind"]) # image kindprint(analysis["analysis"]["edge_density"])print(analysis["decision"])Compare an SVG against the source
Section titled “Compare an SVG against the source”# Compute quality metrics between raster and SVGmetrics = edgesvg.compare("logo.png", result["svg"])print(f"SSIM: {metrics['ssim']:.4f}")print(f"Fidelity: {metrics['fidelity_score']:.4f}")print(f"Color sim: {metrics['color_similarity']:.4f}")print(f"Topology: {metrics['topology_score']:.4f}")Vectorization Methods
Section titled “Vectorization Methods”| Method | When to use |
|---|---|
auto | Delegate method choice to EdgeSVG (recommended for most cases) |
logo | Logos, icons, and geometric shapes — clean minimal paths |
premium | Higher-fidelity conversion for richer images |
smart | Iterative search under SSIM and file-size constraints |
# Logo mode — clean paths, minimal complexityresult = edgesvg.vectorize("icon.png", method="logo")
# Premium mode — higher fidelityresult = edgesvg.vectorize("illustration.png", method="premium")
# Smart mode — hit a target SSIMresult = edgesvg.vectorize("complex.png", method="smart")Full API
Section titled “Full API”import edgesvg
# Vectorize (main entrypoint)result = edgesvg.vectorize( path="input.png", # path to input image method="auto", # method: auto, logo, premium, smart)
# Inspect / analyzeinfo = edgesvg.inspect("input.png")analysis = edgesvg.analyze("input.png")
# Compare existing SVG with raster sourcemetrics = edgesvg.compare("input.png", svg_string)
# Optimize an SVG (coordinate rounding, noise removal)optimized = edgesvg.optimize_svg(svg_string, precision=2)
# Render SVG to PNG bytespng_bytes = edgesvg.render_png(svg_string, width=512, height=512)
# Batch benchmark a directoryreport = edgesvg.benchmark( input_dirs=["images/"], output_dir="results/",)
# SDK versionprint(edgesvg.version())Save and Load
Section titled “Save and Load”import edgesvg
result = edgesvg.vectorize("logo.png", method="auto")
# Save SVGwith open("logo.svg", "w", encoding="utf-8") as f: f.write(result["svg"])
# Render a PNG previewpng_bytes = edgesvg.render_png(result["svg"], 512, 512)with open("preview.png", "wb") as f: f.write(png_bytes)CLI entry point
Section titled “CLI entry point”The Python package also exposes an edgesvg console command:
edgesvg convert logo.png logo.svg --method auto --jsonBuild from source
Section titled “Build from source”git clone https://github.com/raphaelmansuy/edgesvg.gitcd edgesvgcd sdks/pythonpip install maturinmaturin develop --releaseRequires Rust 1.82+.