Skip to main content

Python wrapper for GoFish Graphics - JavaScript is the source of truth for rendering

Project description

GoFish Python

Python wrapper for GoFish Graphics, a declarative charting library.

Important: JavaScript is the source of truth for all rendering, layout, and reactivity. This Python package provides a syntax-similar API that translates Python calls to JavaScript execution. All interactive and animated graphics are handled by SolidJS in JavaScript.

Installation

Using pip

# Install the package
pip install gofish-graphics

# Install a JavaScript bridge (choose one):
pip install pythonmonkey  # Recommended
# OR
pip install jsbridge

Using uv (Recommended)

# Install uv: https://github.com/astral-sh/uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install the package
uv pip install gofish-graphics

# Install a JavaScript bridge (choose one):
uv pip install pythonmonkey  # Recommended
# OR
uv pip install jsbridge

You also need the GoFish JavaScript bundle. Either:

  1. Install it as a sibling package in your monorepo
  2. Set GOFISH_JS_PATH environment variable to the dist directory
  3. The package will try to auto-detect it in common locations

Quick Start

from gofish import chart, spread, rect

# Data
alphabet = [
    {"letter": "A", "frequency": 28},
    {"letter": "B", "frequency": 55},
    {"letter": "C", "frequency": 43},
]

# Create chart (JavaScript executes all rendering)
chart(alphabet).flow(spread("letter", dir="x")).mark(rect(h="frequency")).render(w=500, h=300, axes=True)

Architecture

JavaScript as Source of Truth

This wrapper follows the same pattern as Plotly and Bokeh:

  • Python: Provides the API, data, and configuration
  • JavaScript: Handles all rendering, layout computation, and reactivity

All GoFish features work through JavaScript:

  • SolidJS reactivity for animations
  • Interactive graphics via DOM events
  • Complex layouts and coordinate transforms
  • SVG rendering

How It Works

  1. Python API: You write Python code with syntax similar to JS GoFish
  2. Translation: Python calls are converted to JavaScript function calls
  3. Execution: JavaScript (via bridge) executes GoFish code
  4. Rendering: SolidJS renders interactive SVG to DOM or HTML

Usage

Basic Chart

from gofish import chart, spread, rect

data = [{"x": 1, "y": 10}, {"x": 2, "y": 20}]

chart(data).flow(spread("x", dir="x")).mark(rect(h="y")).render(w=500, h=300)

Stacked Bar Chart

from gofish import chart, spread, stack, rect

chart(data).flow(
    spread("category", dir="x"),
    stack("series", dir="y")
).mark(rect(h="value", fill="series")).render(w=500, h=300, axes=True)

With Pandas

import pandas as pd
from gofish import chart, spread, rect

df = pd.DataFrame({
    "category": ["A", "B", "C"],
    "value": [10, 20, 30]
})

chart(df).flow(spread("category", dir="x")).mark(rect(h="value")).render()

Jupyter Notebooks

from gofish import chart, spread, rect, display_jupyter

node = chart(data).flow(spread("x", dir="x")).mark(rect(h="y"))
display_jupyter(node, w=500, h=300, axes=True)

API Reference

Core Functions

  • chart(data, **options) - Create a new chart
  • ChartBuilder.flow(*operators) - Add operators
  • ChartBuilder.mark(mark) - Apply a mark
  • GoFishNode.render(**options) - Render the chart

Operators

  • spread(field, dir="x", ...) - Spread groups
  • stack(field, dir="y", ...) - Stack groups
  • scatter(field, x, y, ...) - Scatter plot positioning
  • group(field) - Group by field
  • derive(fn) - Transform data
  • normalize(field) - Normalize values
  • repeat(field) - Repeat items
  • log(label) - Debug logging

Marks

  • rect(w, h, fill, ...) - Rectangles
  • circle(r, fill, ...) - Circles
  • line(stroke, ...) - Lines
  • area(stroke, opacity, ...) - Areas
  • scaffold(w, h, ...) - Invisible guides
  • select(layer_name) - Select from layer

Development

Setup with uv (Recommended)

# Clone repository
git clone <repo-url>
cd packages/gofish-python

# Install uv: https://github.com/astral-sh/uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install in development mode with all dependencies
uv sync

# This installs:
# - Package in editable mode
# - Dev dependencies (pytest, black, mypy)
# - Optional dependencies available via extras

Setup with pip (Alternative)

# Clone repository
git clone <repo-url>
cd packages/gofish-python

# Install in development mode
pip install -e ".[dev]"

# Install JavaScript bridge
pip install pythonmonkey

Building GoFish JS Bundle

The Python wrapper needs the compiled GoFish JavaScript bundle:

# In packages/gofish-graphics
pnpm install
pnpm build

Development Commands

# Run tests
uv run pytest
# or
make test

# Format code
uv run black gofish_python/

# Type checking
uv run mypy gofish_python/

# Build distribution
uv build
# or
make build

# Clean build artifacts
make clean

Publishing

See PUBLISHING.md for detailed publishing instructions.

Quick version:

# 1. Update version in pyproject.toml
# 2. Build
uv build
# or
make build

# 3. Publish to PyPI
uv publish
# or
make publish

# Or test on TestPyPI first
make testpypi

Limitations

  1. JavaScript Bridge Required: You must install either pythonmonkey or jsbridge
  2. JS Bundle Required: The GoFish JavaScript bundle must be available
  3. DOM Environment: For interactive rendering, a DOM (browser/Jupyter) is needed
  4. Performance: Python↔JavaScript interop has overhead; complex animations may be slower

Future Work

  • Better DOM-less rendering (static SVG export)
  • Improved error messages
  • Type hints and type checking
  • More comprehensive examples
  • Event handling from Python
  • Animation control from Python

License

MIT

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

gofish_graphics-0.1.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

gofish_graphics-0.1.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file gofish_graphics-0.1.0.tar.gz.

File metadata

  • Download URL: gofish_graphics-0.1.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gofish_graphics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4c690f28ea0e7434567ab881bcb4e9a0c86ee6d1e03e499bde4e63d000afd1a4
MD5 86a246b5131724359fe94c4a25e6e9e0
BLAKE2b-256 6a1c215f89178e0dfdd8da16c4aee471ccc5a5e64ea7d0b0beaa473795f60195

See more details on using hashes here.

File details

Details for the file gofish_graphics-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gofish_graphics-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gofish_graphics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce8efc38bde122dbcaf0af734f036473cb3b7fda17d5c0e8469dd48b6d275dab
MD5 6e7354d509e1310e055e7a447ead3e21
BLAKE2b-256 ee13e32a364f7217015c94e599ad8164fbf49b83e0ee8a261490da5a5594a083

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