Skip to main content

Clean AST implementation for GoFish graphics library

Project description

gofish-python

A Python wrapper for the GoFish graphics library. Supports the mid-level chart API for now. The low-level API is not supported yet. (See notes/design.md and notes/implementation.md for more details.)

Note: This package uses uv for fast package management and testing.

Prerequisites

  • Python 3.8+
  • uv - Fast Python package manager
  • Node.js (for building the widget bundle)
  • pnpm (for managing Node.js dependencies)

Installation

This package uses uv for fast package management.

cd packages/gofish-python
uv pip install -e .

Installing Node.js Dependencies

If you need to build the widget bundle, install Node.js dependencies:

pnpm install

Usage

from gofish import chart, spread, stack, rect

# Create a chart specification
data = [{"lake": "A", "species": "B", "count": 10}]
c = (
    chart(data, options={"w": 800, "h": 600})
    .flow(
        spread("lake", dir="x", spacing=64),
        stack("species", dir="y", spacing=0),
    )
    .mark(rect(h="count", fill="species"))
)

# Convert to JSON IR
ir = c.to_ir()
print(ir)
# {
#     "data": None,
#     "operators": [
#         {"type": "spread", "field": "lake", "dir": "x", "spacing": 64},
#         {"type": "stack", "field": "species", "dir": "y", "spacing": 0}
#     ],
#     "mark": {"type": "rect", "h": "count", "fill": "species"},
#     "options": {"w": 800, "h": 600}
# }

IR Format

The JSON IR has the following structure:

{
  "data": null,
  "operators": [
    { "type": "spread", "field": "lake", "dir": "x", "spacing": 8 },
    { "type": "derive", "lambdaId": "uuid-here" },
    { "type": "stack", "field": "species", "dir": "y" }
  ],
  "mark": { "type": "rect", "h": "count", "fill": "species" },
  "options": {}
}

Building

Building the Widget Bundle

The widget bundle is a self-contained JavaScript module that includes all dependencies. Build it with:

# From the package directory
pnpm run build:widget

# Or directly with Node.js
node build-widget.mjs

This will:

  • Bundle the TypeScript widget source (widget-src/index.ts)
  • Include all dependencies (gofish-graphics, solid-js, apache-arrow)
  • Output to gofish/_static/widget.esm.js

Note: The build process will automatically use gofish-graphics/dist/index.js if available, otherwise it falls back to the package import. Make sure gofish-graphics is built first if you're developing locally.

Running Tests

Python Unit Tests

# Install with test dependencies
uv pip install -e ".[test]"

# Run all tests
uv run pytest

# Or run directly if installed
pytest

# Run specific test file
pytest tests/test_ast.py

# Run with verbose output
pytest -v

Jupyter Notebook Tests

The package includes Jupyter notebooks for interactive testing:

  • tests/test_ir.ipynb - Tests for IR generation
  • tests/test_rendering.ipynb - Tests for widget rendering

To run these:

# Start Jupyter
jupyter notebook

# Or use the provided script (if available)
./run_notebook.sh

Development Workflow

  1. Install dependencies:

    uv pip install -e ".[test]"
    pnpm install
    
  2. Make changes to Python code or widget TypeScript source

  3. Build widget (if you modified widget code):

    pnpm run build:widget
    
  4. Run tests:

    pytest
    
  5. Test in Jupyter (optional):

    jupyter notebook tests/test_rendering.ipynb
    

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.1.dev20260710.tar.gz (910.7 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.1.dev20260710-py3-none-any.whl (911.8 kB view details)

Uploaded Python 3

File details

Details for the file gofish_graphics-0.1.1.dev20260710.tar.gz.

File metadata

File hashes

Hashes for gofish_graphics-0.1.1.dev20260710.tar.gz
Algorithm Hash digest
SHA256 8ff0616b0e1356995efc239fc89016d0533ab5b7dabf7bba21976102d0a6f827
MD5 20713c02b90dec1d18d83209aa95807b
BLAKE2b-256 c38fa1c060ee226466771e5e4c0b9c96e99fe184b21d26ce60546e26887c68d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for gofish_graphics-0.1.1.dev20260710.tar.gz:

Publisher: release.yml on gofish-graphics/gofish-graphics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gofish_graphics-0.1.1.dev20260710-py3-none-any.whl.

File metadata

File hashes

Hashes for gofish_graphics-0.1.1.dev20260710-py3-none-any.whl
Algorithm Hash digest
SHA256 e85f7353b4c979ec497b21d9bec26d2e86357e8ef265fcb6138b28fd27c95ab4
MD5 8e6d84a7a3060ceb17b131c45a7d2c5a
BLAKE2b-256 7b746e12f53ab2672415150a627510db52d882625b06e87a5e26b7b76d7833d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for gofish_graphics-0.1.1.dev20260710-py3-none-any.whl:

Publisher: release.yml on gofish-graphics/gofish-graphics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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