pySVG - Creating SVG with Python

pySVG is a pure Python library to create SVG documents. Essentially it is a python wrapper around svg with the goal to allow people to “program svg”. pySVG can be used to produce svg as an outcome of algorithms you implement (like koch curves, Lindenmayr systems etc.)

Working with pySVG is pretty straightforward. There is a small tutorial in the docs folder but i would suggest refering to the testclasses in the source.

Current status:

Pretty much all elements should be implemented. Type checking, validation and value constraints are NOT. In short: currently you can fill any element with more or less any content. Loading and storing of SVG images also works.

Features

  1. Shapes (circle, ellipses, rectangles, lines, polygons, polylines,paths)
  2. Text
  3. Containers (g-element, defs)
  4. Style attributes (stroke, filling, font)
  5. Transform (in groups)
  6. Filters
  7. Load/Store SVG files

License & Donation

BSD - Style:

Copyright (c) 2008-2012, Kerim Mansour

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project.

If you enjoy using pySVG, please considering making a small donation to support further development. See the Donation page for more information.

Downloads

pySVG can be found here (svn is far more current at the moment:

  1. latest sources (may require a login)
  2. latest release (usually somewhat older, either as dist or with docs and examples)

Acknowledgements

SVG is a huge format. Some things i already tested, some i already “think to have” implemented but didn’t test and others again i didn’t implement yet or only made stubs. I can’t possibly test all and frankly i am not really a graphics guru. So I will list anybody here who provides me with code testing yet untested but theoretically implemented features.

So IF you happen to create any image using pySVG and the code contains elements and attributes that haven’t been tested yet, i would gladly include you in the list along the “feature” you determined to work correctly.

Installation and Requirements

pySVG requires Python (i use version 2.6, other versions may or may not work). pySVG also requires … nothing else :-)

Discussion List

On request

Releases/History

10/12/2010 Release 5 : Version 0.2.1:

  • Added
    • added **kwargs to make life a bit easier when instantiating objects
    • added dropshadows (contributed by Bastian)
    • added patterns
    • added turtle graphics
    • added clip element
    • added use element
    • added some methods to get size/edge points or move an element (depends on element)
    • implemented feMergeNode subclassing
    • added filterprimitiveswithin
  • Corrections
    • setfilter had wrong parameter
    • corrected intendation
    • documentation corrected

09/29/2009 Release 4 : Version 0.2.0:

  • Complete rewrite of the class hirarchy (multiple inheritance)
  • most if not all all elements should exist now
  • gradients supported
  • filters supported
  • Parser implemented that loads svg structures into python
  • TODO:
    • type and content validation (lower priority)
    • better usage of defs and use commands (higher priority)
    • rewrite this post and bring it up to date;)

02/27/2009 Release 3 : Version 0.1.6:

  • Path now supported (although not optimized)
  • lineto (horizontal/vertical/free)
  • moveto
  • cureveto (cubic, quadratic, closecurve)
  • arc
  • included epidoc (still much to document though)

02/02/2008 Release 2 : Version 0.1.5:

  • Extracted ObjectHelper
  • style is now a dictionary instead of a class.
  • included transforms (rotation tested so far)
  • for style and transforms i created some Helperclass to create the dicts for those that do not know the attribute names
  • included a “benchmark” now. Just compare the svg here to the created one to see what still is missing as features.
  • broke the tutorial, see the testcode.

01/29/2008 Release 1 : Version 0.1:

  • Basic features work. You can draw circles, ellipses, rectangles, lines, polylines and polygones. Filled and empty with different fill colors, stroke colors and stroke widths.
  • Documentation is under way
  • setup.py should work
  • Not working is all the fancy stuff like transforms, gradients, ids etc. Style attributes not mentioned below MAY already work, i just didn’t test them all yet. If YOU want to test see “Acknowledgments” below.