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 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.0.tar.gz (7.1 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.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: savage_generator-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 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.0.tar.gz
Algorithm Hash digest
SHA256 e561b25d343f63ce57eef05df1e9184e663dc458e6564bd35326e78975118275
MD5 e0c328a4415fe2220cd4317e68514b45
BLAKE2b-256 c1441500661504646bd1a751aa804e1c5d57adc4d5dba9c9dde6c835e1dd2f2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for savage_generator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a50e54ac025c7c1912920e4959bcf4f658b48c561adf8a973e2f1053a061b5c
MD5 ca23a96b7cb390bf4845eb0f360f55f9
BLAKE2b-256 374c87c6ce61e359db74d78726266bd5bd601524422196ffa7bcb849308d085d

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