Skip to main content

A pure-Python library for rendering professional CS graphics.

Project description

Tesserax: A Lightweight SVG Rendering Library

PyPI version Python versions Tests Coverage Downloads License: MIT

Tesserax is a modern Python 3.12 library designed for programmatic SVG generation with a focus on ease of use, layout management, and flexible geometric primitives. It is particularly well-suited for visualizing data structures, algorithms, and technical diagrams.

Beyond static diagrams, Tesserax now includes a deterministic physics engine and a cinematic animation system, making it a complete toolkit for scientific communication.

Key Features

  • Rich Primitives: Includes standard shapes (Rect, Circle) plus advanced procedural geometry like Polyline with smoothing and subdivision support.
  • Declarative Layouts: Effortlessly arrange shapes in Row, Column, or Grid containers, or use algorithmic layouts like Tree and Force.
  • Smart Canvas: Automatically fit the canvas viewport to the content with adjustable padding.
  • Anchor System: Connect shapes using semantic anchors like top, bottom, left, right, and center.
  • Cinematic Animations: Create complex motion graphics using a declarative, code-first API that supports keyframes, morphing, and warping.
  • Physics Simulation: Bake high-precision rigid body simulations directly into your animations using the built-in World and Body primitives.
  • Reactive Statistical Visualization: Build data-driven graphics with an Altair-inspired API that supports automatic axis generation and seamless Enter-Update-Exit animations.
  • Rock-Solid Reliability: 90% test coverage ensuring predictable behavior across all geometric, layout, and animation systems.

Installation

Tesserax has zero dependencies (literally). It's 100% pure Python, and can be easily installed with pip:

pip install tesserax

Or if you're one of the cool kids, using uv:

uv add tesserax

If you want support for saving PNG files, install with the export extra:

pip install tesserax[export]

Quick Start

The following example demonstrates how to create a simple logo and highlights the most basic functionality of Tesserax.

import math
from tesserax import Canvas, Square, Circle, Text, Polyline, Point, Group
from tesserax.layout import RowLayout

with Canvas() as canvas:
    # We use a top-level row layout
    with RowLayout(align="end") as logo:
        # Left Block
        r = Square(30, fill="green", stroke="none")

        # Center Text
        t = Text(
            "tesserax",
            size=48,
            font="sans-serif",
            fill="navyblue",
            anchor="middle",
            baseline="bottom",
        )

        # Right Circle
        c = Circle(20, fill="red", stroke="none")

    # Create the "Squiggly" Underline
    Polyline(
        [
            r.anchor("bottom").dy(10),
            c.anchor("bottom").dy(10),
        ],
        smoothness=1.0,
        stroke="black",
        marker_end="arrow",
    ).subdivide(5).apply(
        lambda p: p.dy(math.sin((p.x / logo.bounds().width * 20 + 5)) * 5)
    )

# Use fit() to frame the logo perfectly
canvas.fit(padding=10).display()

The display() method in the Canvas class is an IPython/Jupyter/Quarto compatible shortcut to automatically include the rendered SVG (in all its beautiful vectorial glory) directly in a notebook. But you can also use Canvas.save() to generate a plain old, boring SVG file on this, and str(canvas) to get the actual SVG code as a plain string.

Deep Dive: Beyond the Basics

Tesserax scales from simple scripts to complex simulations. Here is an overview of the advanced capabilities available.

Geometric Primitives & Procedural Shapes

Tesserax provides a robust suite of atoms like Rect, Circle, Ellipse, and Arrow.

  • Polyline API: The Polyline class supports smoothing (Bezier interpolation), subdivision (increasing resolution), and simplification (reducing vertices).
  • Path API: For low-level control, use the Path class with standard SVG commands (move_to, cubic_to, arc).

The Layout Engine

Forget manual pixel pushing. Tesserax offers a hierarchy of layout engines:

  • Standard Layouts: Row, Column, and Grid automatically position elements based on gaps and alignment.
  • Hierarchical Layout: Automatically draws Trees and Directed Acyclic Graphs (DAGs).
  • Force-Directed Layout: Simulates physical forces to arrange arbitrary network graphs.

Cinematic Animation

The animation system is designed for storytelling, not just movement.

  • Declarative API: Compose animations using parallel (|) and sequential (+) operators.
  • Keyframes: Define complex multi-stage timelines for any property (position, rotation, color).
  • Morphing & Warping: Smoothly transform one shape into another or apply wave functions to geometry.

Physics Engine

Tesserax includes a baked physics engine for high-precision rigid body simulations.

  • Deterministic: Define a World, add Body objects, and apply Fields like Gravity or Drag.
  • Baked Playback: The simulation is calculated upfront and converted into standard keyframes, allowing high-resolution physics (e.g., 1000 steps/sec) to play back smoothly at any framerate.
  • Interoperable: Physics animations can be mixed and matched with standard tweens.

Statistical Visualization

Bridging the gap between diagrams and plots, Tesserax offers a grammar-of-graphics charting API.

  • Altair-lite API: Define a Chart, select a Mark (bar, point), and encode visual channels like x, y, and color.
  • Automated Scales: Includes built-in Linear, Band, and Color scales that automatically map data values to pixels and palettes.
  • Integrated Axes: Effortlessly add titles, ticks, and gridlines with smart coordinate management.

Why Tesserax?

In the Python ecosystem, there is a clear divide between data visualization (plotting numbers) and diagrammatic representation (drawing concepts).

Tesserax is for Scientific Drawing---providing the low-level primitives needed for total layout authority.

Libraries like Matplotlib map data to charts. Tesserax maps concepts to geometry. Use Tesserax for the schematics, geometric proofs, and algorithmic walkthroughs in your papers.

TikZ is the industry standard for academic figures but uses a cryptic macro language. Tesserax brings that same "total-control" philosophy to Python 3.12, giving you coordinate-invariant precision with the power of Python's loops and types.

Contribution

Tesserax is free as in both free beer and free speech. License is MIT.

Contributions are always welcomed! Fork, clone, and submit a pull request.

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

tesserax-0.10.0.tar.gz (168.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tesserax-0.10.0-py3-none-any.whl (54.0 kB view details)

Uploaded Python 3

File details

Details for the file tesserax-0.10.0.tar.gz.

File metadata

  • Download URL: tesserax-0.10.0.tar.gz
  • Upload date:
  • Size: 168.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tesserax-0.10.0.tar.gz
Algorithm Hash digest
SHA256 0b05e7a48f0b0fa9e6c1debcfbba74b5d1b7d10b81b61618c25667efe43e11be
MD5 8049d575d3b5d18a6f5721de61e4997e
BLAKE2b-256 d895a25947564b1163bf8583af4c2b5988a70b5d50fc322e166737d06a1f9302

See more details on using hashes here.

File details

Details for the file tesserax-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: tesserax-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 54.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tesserax-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f13bb29586f4c86876371f78aa77d238b7c2c0163ca5ab8002aa83ac0f1c477
MD5 6e00f329e2494307cc20fc7fdb153ff2
BLAKE2b-256 09f3399fc107a79fad562ccbfccc298ad78f56e0a0a576d6c95e706966040ff1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page