Skip to main content

pysvglabel

Label generator with SVG templates supporting embedded Python code and CSV data

Template Output
Design Template
source SVG
with supporting code
Generated Labels
from data CSV

Usage

Install: pip install pysvglabel

To generate a sheet of labels from a template file and csv, run: python -m pysvglabel.generate <template.svg> <data.csv> <output.svg | output.pdf>

Additional options (see command help for details):

  • generate (Inkscape nonstandard) multi-page SVGs
  • send to printer (Windows only)

If PDF output is requested, Inkscape is used as the renderer and must be installed and on your system PATH.

Label sheet data is embedded in the template .svg file. All text in the .svg file is treated as Python f-strings, and the contents of the row (where the column name is a legal Python variable name) are made available. Specially formatted commands (see Template Reference) that call Python functions (such as generating barcodes) can also be written into the template.

Security notes: running the labelmaker can execute arbitrary Python code embedded in the template SVG and supporting scripts. There should be no issues if you're designing your own template from scratch. Treat templates from the internet as you might treat a document with macros - make sure you trust it before running it. Not all embedded Python code may be visible graphical elements.

Windows Live Printing

The live printing utility watches for changes in a .csv file and prints changed rows. This is useful for single label printers (as opposed to sheets), like a thermal printer.

This needs a few more dependencies: pip install pysvglabel[winprint]

Inkscape must be installed and on your system PATH.

Run python -m pysvglabel.printer <printer-name> <template.svg> <data.csv>

API

The SVG templating engine can be used in other Python code with the SvgTemplate class.

from pysvglabel import SvgTemplate
import xml.etree.ElementTree as ET

template = SvgTemplate("template.svg")
# create the blank sheet
sheet = template.create_sheet()
# instantiate a page of labels and append to the sheet, with values specified as a list of dicts, one per label
sheet.append(template.apply_page([
  {'title': 'cat', 'barcode': '0000'},
  {'title': 'duck', 'barcode': '0001'},
]))

# ... which can be written out
ET.tostring(sheet, 'utf-8')

# ... or rendered to PNG
import cairosvg
cairosvg.svg2png(bytestring=ET.tostring(sheet, 'utf-8'))

Template Reference

Control Block

The control block is a textbox starting with # pysvglabel: init This is interpreted as a block of Python code, executed for each template. Variables and imports are available to code running per label instance.

It must define the sheet as a LabelSheet object, for example sheet = LabelSheet(page=(40, 10)*mm, space=(0, 0)*mm, count=(1, 1))

Labels

For each label instance, the CSV data is made available as local variables of the column name. Values can also be accessed through row['column name'], especially if the column name is not a valid Python variable name.

All text is interpreted as f-strings, use {} to substitute in variable values.

Rectangular Area Generators

These are defined as a rectangle (specifying the area) and a textbox (with the Python code, starting with the snake emoji 🐍) in a group.

Barcodes:

  • Code128(data: str, thickness: LengthDimension, quiet: bool = True, align: Align = Align.CENTER, fill: str = '#000000'): code 128 linear barcode generator, a general-purpose barcode
  • QrCode(data: str, size: LengthDimension, align: Align = Align.CENTER, fill: str = '#000000', border: Optional[int] = None, error_correction: Optional[int] = None): QR code generator
  • DataMatrix(data: str, size: LengthDimension, align: Align = Align.CENTER, fill: str = '#000000'): datamatrix 2d barcode generator

Sub-elements:

  • Svg(filename: Optional[str], scaling: Scaling = Scaling.FIT, align: Align = Align.CENTER): include a SVG, with the filename relative to the template SVG's path. If filename is None, this is ignored.
  • Subtemplate(filename: Optional[str], env: Dict[str, Any], scaling: Scaling = Scaling.FIT, align: Align = Align.CENTER): include a template SVG file, applying the templating engine to it.

Modifiers

These are defined as some elements and a textbox (with the Python code, starting with the snake emoji 🐍) in a group.

  • Hide(cond: bool): if cond is true, hides the elements
  • StyleModifier(attribs: Dict[str, str]): sets the argument style attributes of all elements in the group.
  • FillColor(color: str), StrokeColor(color: str): sets the fill / stroke color of all elements in the group. Alpha value (if specified as #rrggbbaa) is mapped to fill-opacity / stroke-opacity.
  • DimensionModifier(set: Dict[str, LengthDimension], add: Dict[str, LengthDimension] = {}): sets or adds attributes of all elements in the group.

Metadata

Release files for pysvglabel 0.1.0

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

Source distribution (sdist)

Source distribution for pysvglabel 0.1.0
File Size Uploaded
pysvglabel-0.1.0.tar.gz 25.9 kB Details

Built distribution (wheel)

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

Total release size: 57.1 kB

Release files / pysvglabel-0.1.0.tar.gz

Download URL pysvglabel-0.1.0.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cbbeae2c4e89e7cebd4adb9de75a0a879d61b8fc8f08338d1e931f364b1e6aee
BLAKE2b-256 checksum
How to use checksums
d77b0419c26ce065f606a50ec82edab8ff3818fcbf1602495e7ab06be86eef71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.

Transparency log

Release files / pysvglabel-0.1.0-py3-none-any.whl

Download URL pysvglabel-0.1.0-py3-none-any.whl
Size 31.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01e28db0e63840ca538246b1500677f766c14a60c60329de3bd34e2bf7d40543
BLAKE2b-256 checksum
How to use checksums
4b7cce13d2e226aa54eafdf06e730de2cb91414cf888e23ca79782b0da7c71ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 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