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.2.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.2-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: savage_generator-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 40d0c66bf9fb05c7a711af9bd7042d0b1df91d00d78f6045b63c9bee01638fe3
MD5 8f8c6947a17b18f74430c491328f0f50
BLAKE2b-256 0f5357f67a035216cbe0ca873bb15a97282f054d038d4766fa2eb6d9bda7e759

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for savage_generator-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 69467e47eeec94ad06fdfb60370fd3b87e314c6f7ba97e8036089d756f32d088
MD5 2f5a4dee2edb081acbb20654b0a99338
BLAKE2b-256 2c7fa50b1a4a5eea14f895251549ff9d45ca9a52ea7f4f22be2eebdd1d37d977

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