Skip to main content

GenomeSpy for Python logo

genome-spy-python

CI status PyPI version Open brush example in Colab

genome-spy-python is a Python interface for GenomeSpy, a grammar for interactive and scalable genomic visualization. It lets Python users build GenomeSpy specifications with a declarative, fluent API, serialize them to JSON, and display them in Jupyter or Marimo notebooks.

Read the documentation for the getting-started guide, user guide, examples, and API reference.

Altair is the project's main source of inspiration. This codebase follows Altair's approach of combining schema-backed specification objects with a small handwritten Python API for marks, encodings, composition, and rendering. It adapts that model to GenomeSpy's genomics-native grammar: locus scales, genomic data sources, and coordinated genomic views.

The project is under active development. The current focus is the reusable GenomeSpy Core grammar and notebook rendering; GenomeSpy App-specific features will come later.

Installation

The package requires Python 3.11 or newer.

From PyPI:

pip install genome-spy-python

From source:

pip install uv
git clone https://github.com/genome-spy/genome-spy-python.git
cd genome-spy-python
uv sync

For notebook use, install with Arrow support. This includes PyArrow for dataframe transport:

pip install "genome-spy-python[arrow]"

See creating and updating charts in notebooks for supported tables and live updates.

See the getting-started guide for the first example.

Examples

import genome_spy as gs

chart = (
    gs.Chart(
        [
            {"x": 1, "y": 4, "group": "A"},
            {"x": 2, "y": 3, "group": "B"},
            {"x": 3, "y": 5, "group": "A"},
        ]
    )
    .mark_point(size=80)
    .encode(
        x="x:Q",
        y="y:Q",
        color="group:N",
    )
)

chart

GenomeSpy also has locus-scaled axes for genomic coordinates. This small example renders intervals along a region of chromosome 1:

import genome_spy as gs

intervals = [
    {"chrom": "chr1", "start": 100, "end": 220, "name": "gene A"},
    {"chrom": "chr1", "start": 280, "end": 420, "name": "gene B"},
]

chart = (
    gs.Chart(intervals)
    .mark_rect()
    .encode(
        x=gs.Locus("chrom", "start"),
        x2="end:Q",
        y="name:N",
        color="name:N",
    )
)

chart

Charts can be serialized to a portable GenomeSpy specification or standalone HTML:

chart.to_json()
chart.save("intervals.html")

Update data without recreating the chart

For reactive Jupyter or Marimo notebooks, create a widget with an explicitly named dataset and replace that dataset as inputs change. The browser keeps the existing GenomeSpy instance, so view state such as zoom is preserved.

chart = (
    gs.Chart(data={"name": "table"}, datasets={"table": []})
    .mark_point()
    .encode(x="x:Q", y="y:Q")
)
view = chart.widget()

view.set_dataset("table", updated_dataframe)

See creating and updating charts in notebooks for the Marimo pattern.

Contributing

Contributions are welcome. See CONTRIBUTING.md for development setup, testing, code generation, documentation, gallery, and pull-request guidelines.

References

  • GenomeSpy — the upstream visualization grammar and JavaScript renderer.
  • Altair — a schema-wrapper design reference.
  • Gos — a related grammar and Python-wrapper design reference for genomics visualization.

Portions of the schema-wrapper implementation and selected tests are adapted from Altair under its BSD-3-Clause license. See Third-party notices for the exact sources and license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genome_spy_python-0.3.0.tar.gz (10.1 MB view details)

Uploaded Source

Built Distribution

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

genome_spy_python-0.3.0-py3-none-any.whl (4.8 MB view details)

Uploaded Python 3

File details

Details for the file genome_spy_python-0.3.0.tar.gz.

File metadata

  • Download URL: genome_spy_python-0.3.0.tar.gz
  • Upload date:
  • Size: 10.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for genome_spy_python-0.3.0.tar.gz
Algorithm Hash digest
SHA256 12e41bf37633708e548fc9d31803d63538815bd2a7dc46328422578a30d335e8
MD5 d6c748ecf4bd5e765aadde178192cc69
BLAKE2b-256 da289d0ceb1b89dc8eb8606fb6589e3fa4faf486dd3bac76e5c60c23a8c6e81b

See more details on using hashes here.

Provenance

The following attestation bundles were made for genome_spy_python-0.3.0.tar.gz:

Publisher: release.yml on genome-spy/genome-spy-python

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

File details

Details for the file genome_spy_python-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for genome_spy_python-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f705f68ac0db3fab0fdc6497173dcf472f1cb626eac1fc1a71b854b5f65c3191
MD5 5391adf8e0a9f02eb8d3595fa59dc814
BLAKE2b-256 fe3c98688a9f589366ec5eb7004e43ac9c78cc4b8cb1c681741711ef17e62d73

See more details on using hashes here.

Provenance

The following attestation bundles were made for genome_spy_python-0.3.0-py3-none-any.whl:

Publisher: release.yml on genome-spy/genome-spy-python

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

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page