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.3.tar.gz (14.7 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.3-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: savage_generator-0.1.3.tar.gz
  • Upload date:
  • Size: 14.7 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.3.tar.gz
Algorithm Hash digest
SHA256 72c03ec27fee76b7138f6be1d07272d47d7d5f1f35eb85598a462ba79adc3203
MD5 4805cd5dd6f40f5a07f6e72c59d44a44
BLAKE2b-256 01dfbc067f8545d6f2e2103a76c22bb5e3ce09167fe1e52afb90f9279f2fa27b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for savage_generator-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9e869f63279de685c7f4205b9c623fbd07ab112353a4f83420188c3067368530
MD5 065e943dde07d62e73b1b65d195a24ff
BLAKE2b-256 274f59d69347162040893b9556dadf0cf4ac3346175bdd5f03674fb6b3ce8b91

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