Skip to main content

A basic SVG generator in Python

Project description

Savage

Savage is a lightweight and modular SVG generator written in Python. Designed with an object-oriented structure, it lets you build entire SVG documents programmatically — from simple shapes and text to complex, nested groups.

At its core is the Graphic class, which represents a complete SVG document. Combined with a growing library of SVG elements like Circle, Ellipse, Line, Polygon, Polyline, Rect, Text and Group, Savage makes it easy (not really) to construct and style SVG graphics dynamically.

Features

  • ⚙️ Build full SVG documents with the Graphic class
  • 🔵 Create shapes: Circle, Ellipse, Line, Polygon, Polyline, Rect
  • 📝 Add text labels with styling via the Text class
  • 🧩 Group elements together using Group for hierarchical layouts
  • 🎨 Set attributes like position, fill, stroke, font size, and more
  • 🧱 Clean, extensible architecture for adding new SVG element types
  • 🧪 Built-in support for testing and development via pytest

Installation

To install Savage for use in other projects, use:

pip install savage-generator

To install Savage in editable mode (for development), follow these steps:

Clone the repository

git clone https://github.com/jamie-gillett/savage.git
cd savage

Install the package in editable mode

pip install -e .

Installation with test setup

pip install -e .[dev]

Usage

Savage is built around combining individual SVG elements into a full document. You can create shapes and text, organize them into groups, and output valid SVG markup using the Graphic class.

Create and render a simple SVG

from savage import Graphic, Circle, Rect, Text, Group

# Create a red rectangle and a blue circle
rect = Rect(x=10, y=10, width=200, height=100, fill="red")
circle = Circle(cx=110, cy=60, r=40, fill="blue")

# Add a label
label = Text(x=60, y=65, content="Hello SVG!", fill="white", font_size="18")

# Group them together
group = Group(content=[rect, circle, label])

# Create the SVG document and add the group
doc = Graphic(width=300, height=150)
doc.add(group)

# Print the full SVG
print(doc.to_svg())

This will output SVG markup that you can save to a file or embed in a webpage.

Save to a file

# Save the SVG to a file
doc.save("output.svg")

Running Tests

To run the tests, simply run:

Run tests using pytest

pytest

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

savage_generator-0.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

savage_generator-0.1.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file savage_generator-0.1.1.tar.gz.

File metadata

  • Download URL: savage_generator-0.1.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for savage_generator-0.1.1.tar.gz
Algorithm Hash digest
SHA256 81681f49d2abaa5639e2fe712c66488f747602babf27f2e1d215ea7747c3d18d
MD5 de87c78daf0c35a79510ca99f43793f7
BLAKE2b-256 f17b076f7e00aee8ef22a5e2a954e7670b382522073d01214e33927c5520809e

See more details on using hashes here.

File details

Details for the file savage_generator-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for savage_generator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73838bd2af4f8eccc619ffca63c2fee14bf6cea3b5a731d5c20b01a078df7fc7
MD5 dd21e2cf03d146ecf608310ca48c1117
BLAKE2b-256 3d96238f980c91e8aec17d0de10d90654d09ca14d235933dd841b36bf682925c

See more details on using hashes here.

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