Programmable infographic generation powered by sympy and svg.py
Project description
Infogroove
Infogroove converts declarative template definitions into SVG infographics using sympy for formula evaluation and svg.py for SVG generation.
Quick Start
Create the virtual environment and install dependencies with uv:
uv sync
Render any of the bundled examples (each lives in its own subdirectory):
uv run infogroove -f examples/horizontal-bars/def.json -i examples/horizontal-bars/data.json -o examples/horizontal-bars/horizontal-bars.svg
uv run infogroove -f examples/stat-cards/def.json -i examples/stat-cards/data.json -o examples/stat-cards/stat-cards.svg
uv run infogroove -f examples/blue-parallelograms/def.json -i examples/blue-parallelograms/data.json -o examples/blue-parallelograms/blue-parallelograms.svg
uv run infogroove -f examples/arc-circles/def.json -i examples/arc-circles/data.json -o examples/arc-circles/arc-circles.svg
uv run infogroove -f examples/staggered-keywords/def.json -i examples/staggered-keywords/data.json -o examples/staggered-keywords/staggered-keywords.svg
Running Tests
Install development dependencies and execute the test suite with pytest:
uv sync --extra dev
uv run --extra dev pytest
To measure coverage locally you can add the --cov flag:
uv run --extra dev pytest --cov=infogroove --cov=tests
Example Gallery
| Template | Preview |
|---|---|
| Horizontal Bars | |
| Stat Cards | |
| Blue Parallelogram Bands | |
| Arc Circles | |
| Staggered Keywords | |
| Key Messages |
Template Overview
A template definition is a JSON document with these top-level keys:
variables: Global constants available throughout rendering. Definevariables.canvaswith viewportwidthandheight, plus any reusable values such aspalette,margin, orfontFamily. Variables are exposed in the rendering context both undervariablesand as direct names, so a value declared asvariables.radiusis available as{radius}.formulas(optional): Named expressions evaluated with sympy. Results are merged into the rendering context for placeholder substitution. Skip the block entirely when inline expressions are sufficient.elements: A list of SVG element descriptors. Each descriptor has atype, attribute map, optionaltextcontent, and an optionalscope(canvasoritem). Canvas elements are rendered once; item elements repeat for each data record.numElementsRange(optional): Expected minimum and maximum number of data items.
Placeholder syntax supports both {path.to.value} lookups and inline Python
expressions such as {index * 10} or {canvas.width / 2}. Expressions are
evaluated inside the same safe context exposed to formulas (variables, data
fields, derived metrics, and formula results).
CLI Options
uv run infogroove --help
Key flags:
-f, --template: Path to the template definition JSON file (e.g.def.json).-i, --input: JSON file containing an array of data objects.-o, --output: Destination SVG path or-for stdout.
Programmatic Usage
Infogroove exposes a loader for integrating templates directly into Python applications:
from infogroove.loader import load
with open("examples/arc-circles/def.json", encoding="utf-8") as fh:
infographic = load(fh)
svg_markup = infographic.render([{"label": "Alpha", "value": 3}])
Prefer infogroove.loader.load for file objects and infogroove.loader.loads
when the template definition is already in memory as a string. Both helpers
return an InfogrooveRenderer, exposing the parsed template via the
template property for metadata inspection.
When you already have the JSON structure as a Python mapping, instantiate an
infographic directly with the Infogroove factory:
from infogroove import Infogroove
infographic = Infogroove({
"variables": {
"canvas": {"width": 200, "height": 40},
"gap": 10,
},
"formulas": {"x": "index * gap"},
"elements": [
{"type": "circle", "attributes": {"cx": "{x}", "cy": "20", "r": "5"}},
],
})
svg_inline = infographic.render([{}] * 10)
Developing Templates
- Formulas can reference global values (
canvas.width,radius), per-item fields (value,label), and derived metrics (maxValue,averageValue). - Place reusable constants (including canvas dimensions) under
variables. - Provide
scope: "canvas"for static backgrounds and decorations. - Choose between inline expressions and formulas depending on reuse: inline
placeholders handle quick math (
{index * 10}), while formulas remain useful for shared or multi-step calculations.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file infogroove-0.2.1.tar.gz.
File metadata
- Download URL: infogroove-0.2.1.tar.gz
- Upload date:
- Size: 40.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a85480be11e14df081819f9e8117f35c7ba1504d8995627b43ebc2939d47ed6c
|
|
| MD5 |
e92a8d298e57ffe0af182523cb5afa90
|
|
| BLAKE2b-256 |
86f5bd17e72a9696383ed56b3d8cc5bfc85461dc736fffb6aae4e2f6bbbd3be2
|
File details
Details for the file infogroove-0.2.1-py3-none-any.whl.
File metadata
- Download URL: infogroove-0.2.1-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a91b23b1c7197b4afa8c5cdb74c93483e202f169fadb950655c7cbbd60b82eec
|
|
| MD5 |
729ccf5fe3c7eab96347aac113f5b726
|
|
| BLAKE2b-256 |
cac2e3b7c256743401f04e0ecc534668939089f282886bbfb88cd7ee8051c621
|