Skip to main content

Simple python library for programatically building SVG XML. (backed by xml4h https://github.com/jmurty/xml4h)

Why

There are two solid libraries for doing similar things already (pySVG http://codeboje.de/pysvg/ and svgwrite https://pypi.python.org/pypi/svgwrite/), but neither does quite what I find myself needing so succinctly as this.

Installation

pip install simplesvg

Functions

A note on **kwargs

For all of the kwarg-using functions below, any arguments passed will be directly added to the XML elements. Camel case will be converted to hyphenated words automatically (e.g. strokeWidth becomes stroke-width). Common usage of this would be fill, stroke, stroke-width, and id. See example.py for some usage of these.

simplesvg.SVG(width, height, **kwargs)
  • Creates a new SVG document with specified with and height (in pixels). Elements within can exceed these bounds (but they might not be rendered depending on what’s being used to display the SVG).

SVG.to_xml()
  • Serializes the document to XML and returns the resulting string.

SVG.circle(x, y, r, **kwargs)
  • x, y = coordinate for the center of the circle

  • r = radius

SVG.rectangle(x, y, width, height, **kwargs)
  • x, y = coordinate of the upper-left corner of the rectangle

  • width, height = dimensions of the rectangle

SVG.line(x1, y1, x2, y2, **kwargs)
  • x1, y1 = coordinate of the first point.

  • x2, y2 = coordinate of the second point.

SVG.polygon(points, **kwargs)
  • points = an ordered list of pairs representing points on the polygon (e.g. [(1,2), (3,4), (1,6]])

simplesvg.rgb(r, g, b)
  • Helper function that you can pass with fill or stroke to used RGB colors instead of named colors.

See example.py in the repo for usage of all of this.

Metadata

Release files for simplesvg 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simplesvg 0.1.1
File Size Uploaded Provenance Actions
simplesvg-0.1.1.tar.gz 2.5 kB Without provenance Details for simplesvg-0.1.1.tar.gz

Release files / simplesvg-0.1.1.tar.gz

Download URL simplesvg-0.1.1.tar.gz
Size 2.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9e530f648322a9430f98740bc326b4c01a3947198b226f9a2186fca79f1527d4
BLAKE2b-256 checksum
How to use checksums
05a3b05d51b7fa2465659e376a88f49f410c18d165280ee177c3249f360f4f9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for simplesvg 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page