Skip to main content

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

Reason this release was yanked:

package deprecated. use gofish-graphics

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-python

# 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-python

# 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_python-0.1.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: gofish_python-0.1.0.tar.gz
  • Upload date:
  • Size: 16.2 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_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cbba86531a1bbfb01e09d502ee861e9424030dfb9daffc4bc5f374768b3779b5
MD5 9c6455584ad73ef2cc0ff0d22538fe7e
BLAKE2b-256 c1105276af292ef89a532c4424f9ffb871f652b8fae22c63cc0f6155d938260d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gofish_python-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_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbacc9a17d0c3b90d30e85469e8bb14e2c1e5918de780ba16ed7c1db0572add3
MD5 cff1bcc7fe857168d24593d3fd7f852f
BLAKE2b-256 6a7c5ba300a25790b3bf929de070fc964cc54bec162d9d4c4433af0b7888ab32

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