Python wrapper for gum.jsx, a language for creating vector graphics
Project description
A Python wrapper for gum.js, a language for creating visualizations using a React-like JSX dialect that evaluates to SVG. Designed for general graphics, plots, graphs, and network diagrams.
Head to compendiumlabs.ai/gum for a live demo and documentation on the underlying gum.js library. Or see the gum.js repository.
Installation
pip install gum-py
Requires Node.js to be installed for the gum.js backend.
Usage
Create visualizations using Python syntax that generates JSX:
import gum
from gum import C
from gum.gen import Plot, SymLine
# create a simple sine wave plot
plot = Plot(
SymLine(fy=C.sin, stroke=C.blue, stroke_width=2),
xlim=(0, 2*C.pi), ylim=(-1, 1), grid=True, margin=0.2, aspect=2,
)
# display in terminal (requires chafa)
gum.display(plot) # or just `plot` if you're in IPython or Jupyter
# or get the SVG string
svg = gum.evaluate(plot)
# or get the JSX code
jsx = str(plot)
If you're in IPython or Jupyter, you don't even need to call display. Just type plot and it will automatically display the visualization inline.
Pandas Integration
Plot DataFrames directly with high-level functions:
import pandas as pd
import numpy as np
from gum import lines, points, bars
# line plot from DataFrame
th = np.linspace(0, 2*np.pi, 100)
df = pd.DataFrame({ 'sin': np.sin(th), 'cos': np.cos(th) })
lines(df, margin=0.15)
# bar chart from Series
bars(pd.Series({'A': 3, 'B': 8, 'C': 5}))
Symbolic Expressions
Use C for constants and V for variables:
from gum import C, V
from gum.gen import Plot, SymLine, SymPoints
# C references gum.js constants and functions
C.sin, C.cos, C.pi, C.blue, C.red
# build symbolic expressions
decay = lambda x: C.exp(-x/2) * C.sin(3*x)
# V creates named variables bound to data
theta = V.theta(np.linspace(0, 2*np.pi, 100))
CLI
Display gum visualizations directly in the terminal using chafa. Requires a terminal with image support, such as ghostty.
# run a built-in demo
python -m gum -d plot -s 50
# pipe JSX code
cat input.jsx | python -m gum
CLI options:
| Option | Description | Default |
|---|---|---|
-d, --demo <name> |
Run a named demo | - |
-s, --size <size> |
Terminal display size | 50 |
-t, --theme <theme> |
Theme: light or dark |
dark |
Available demos: plot, barplot, network, symline, grid, stack, text, and more (see gum/dem.py).
Jupyter Support
gum.py automatically renders SVG in IPython console and Jupyter notebooks:
from gum import Plot, SymLine, C
# this will display inline in Jupyter
Plot(
SymLine(fy=C.sin),
xlim=(0, 2*C.pi), ylim=(-1, 1), grid=True,
)
Components
gum.py wraps all gum.js components. Key ones include:
Layout: Box, Frame, Stack, HStack, VStack, Grid, Points
Shapes: Rect, Ellipse, Circle, Line, Shape, Spline
Text: Text, TextFrame, Latex, Equation
Plotting: Plot, Graph, Axis, HAxis, VAxis, BarPlot
Symbolic: SymLine, SymPoints, SymShape, SymSpline, SymFill, SymField
Network: Node, Edge, Network, Arrow
See the gum.js documentation for detailed component reference.
Project details
Release history Release notifications | RSS feed
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 gum_jsx-0.4.tar.gz.
File metadata
- Download URL: gum_jsx-0.4.tar.gz
- Upload date:
- Size: 610.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29ac3a752df1c58c57557a3e8967a68121b759fd87dbf0feb285ee1ce6db2eb9
|
|
| MD5 |
6679e2cf4c35d118e9afdd90ac8a308d
|
|
| BLAKE2b-256 |
45a7557858e5869fc152dd3acfb735a34f5838a32ad4e90d2f34ce230ace015c
|
File details
Details for the file gum_jsx-0.4-py3-none-any.whl.
File metadata
- Download URL: gum_jsx-0.4-py3-none-any.whl
- Upload date:
- Size: 609.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02982bf27a2c4a82b54a85eea0e5e62b34828257ba68ddf473aec1a0dcbffae2
|
|
| MD5 |
6549d703843287ae6932d7b751e844e8
|
|
| BLAKE2b-256 |
ef4e910137e05a5b59b6f2bd30b0ec125ade985def93dd7f1281f35a50284865
|