Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.3.2 instead.

pysvglib

A Python-based SVG graphics library for programmatically generating SVG diagrams from basic shapes.

Example

Import the library

import svg

Create a "root" SVG object and define the view box. Keyword arguments define other parameters that will be passed to the fundamental svg node.

root = svg.RootSvg((-25, -25, 50, 50), width='50%', height='50%')

Add style definitions that will affect the entire graphic. Keyword arguments become css style parameters.

root.add_style(svg.Style('.glass', fill='#bbf7f4', fill_opacity=0.5))
root.add_style(svg.Style('.outline', stroke='black'))

Add child nodes and groups of nodes. These can be rectangles, circles, complex paths, etc.

root.append_child(svg.Rectangle(p1=(-10, -15), p2=(30, 85), fill='#cccccc', stroke='none'))

mygroup = svg.Group(id='mygroup')
mygroup.append_child(svg.Rectangle(center=(0, 0), width=5, height=10).append_class('glass'))
mygroup.append_child(svg.Rectangle(center=(3, 2), width=10, height=5).append_class('glass'))
root.append_child(mygroup)

path = svg.Path((6.7, -10), stroke_width=0.2, fill='none')
path.line_to((0, 20), relative=True).h_line(-2, relative=True) \
    .arc_to((12.9, 12.9), 0, False, True, (0, -20), relative=True) \
    .close()
path.append_class('outline')
root.append_child(path)

Apply transformations to nodes and groups.

mygroup.rotate(37, center=(4, 7))
mygroup.translate((2, -4))
path.skew_x(10)

Output the SVG markup as a string.

print(root)

Which results in:

<svg height="100%" viewBox="-25 -25 50 50" width="100%" xmlns="http://www.w3.org/2000/svg">
  <style>
    .glass {
      fill: #bbf7f4;
      fill-opacity: 0.5;
    }
  </style>
  <g id="mygroup">
    <rect fill="#cccccc" height="100" stroke="none" width="100" x="-50" y="-50"/>
    <rect class="glass" height="10" width="5" x="-2.5" y="-5.0"/>
  </g>
  <path d="M 6.7 -10 l 0 20 h -2 a 12.9 12.9 0 0 1 0 -20 Z" fill="none" stroke-width="0.2"/>
</svg>

...or output it to a file:

root.write('my_picture.svg')

which results in:

Simple SVG

Development

Use pipenv for local environment management. After cloning the repository:

$ cd <project-repo>
$ pipenv install -e .[dev]
$ pipenv shell

Run tests by just executing pytest at the root of the local virtual environment. Likewise enforce code style by running pycodestyle . from the root of the local virtual environment.

To package and release, from within the virtual environment:

$ python setup.py sdist bdist_wheel

See also this page.

Metadata

Release files for pysvglib 0.3.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 pysvglib 0.3.1
File Size Uploaded
pysvglib-0.3.1.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pysvglib 0.3.1
File Interpreter ABI Platform
pysvglib-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.7 kB

Release files / pysvglib-0.3.1.tar.gz

Download URL pysvglib-0.3.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
062a4145fb1d6344c9f9d8345ed76a34198fb6297361b6ce37d2f27985b021da
BLAKE2b-256 checksum
How to use checksums
e1c9f8dc51f49464aeb531a0d7cf6bb6a8f1dd9f6a320bddcc40e911c9ae1700
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0

Release files / pysvglib-0.3.1-py3-none-any.whl

Download URL pysvglib-0.3.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
98d0df5a4ddec7644b7822e6ddf10444577951a77245eed50790eb8ddb29bf20
BLAKE2b-256 checksum
How to use checksums
3bfc5e6aace4b629e6e4eeccb508f78bf6e1efe7e276232f30367f1df1ea4543
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0

Release history Release notifications | RSS feed

0.3.2

2 release files

This release

0.3.1 This release

2 release files

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