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.2.0.tar.gz (10.3 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.2.0-py3-none-any.whl (4.8 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: genome_spy_python-0.2.0.tar.gz
  • Upload date:
  • Size: 10.3 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.2.0.tar.gz
Algorithm Hash digest
SHA256 1f0b4b2d04f5573498b8aa5970204cfb14f75a69cc8d845ee21b336b007953bf
MD5 15c26aff74dc7acc87acaf059a865c1f
BLAKE2b-256 500b4a39fe902148f84280af868e5f928e8102490c4e6dc08e095c1d9113fb97

See more details on using hashes here.

Provenance

The following attestation bundles were made for genome_spy_python-0.2.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.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for genome_spy_python-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a22f636b31cd07a48128dac7a6ec9f2dcf73ca4499d248bcf58289e29d95d81
MD5 6aa6fb7d82af8e188f8895d8ffa63771
BLAKE2b-256 88b1b92563f04472a1af14f23cbb12ee600e0e29fb4b0d01d9724c61b86617ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for genome_spy_python-0.2.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

0.3.0

2 files

This release

0.2.0 This release

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