genome-spy-python
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file genome_spy_python-0.1.0.tar.gz.
File metadata
- Download URL: genome_spy_python-0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ebacdb32779d96652e876fbd0dc37cbb3c5d6f70c1edb3c0663702fe173e6f3
|
|
| MD5 |
12f905929f0247ff15fb28d46913687d
|
|
| BLAKE2b-256 |
f3ab60f831f02ed285560c34e66a01b912d7f63ab0b3d524d8d0bb7d8185dbfd
|
Provenance
The following attestation bundles were made for genome_spy_python-0.1.0.tar.gz:
Publisher:
release.yml on genome-spy/genome-spy-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
genome_spy_python-0.1.0.tar.gz -
Subject digest:
2ebacdb32779d96652e876fbd0dc37cbb3c5d6f70c1edb3c0663702fe173e6f3 - Sigstore transparency entry: 2766045703
- Sigstore integration time:
-
Permalink:
genome-spy/genome-spy-python@37eaf35f245c293e8e36365e6a608e03458a4c87 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/genome-spy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@37eaf35f245c293e8e36365e6a608e03458a4c87 -
Trigger Event:
release
-
Statement type:
File details
Details for the file genome_spy_python-0.1.0-py3-none-any.whl.
File metadata
- Download URL: genome_spy_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26811086e6701cfb09b5f31480580993beca36364112b29ea62960b28329c187
|
|
| MD5 |
e114ce1279bf407699d18832ba372cfb
|
|
| BLAKE2b-256 |
8e04d923d86faaaaf2f28549c85e8a0ab0433f260b67add23132839313610304
|
Provenance
The following attestation bundles were made for genome_spy_python-0.1.0-py3-none-any.whl:
Publisher:
release.yml on genome-spy/genome-spy-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
genome_spy_python-0.1.0-py3-none-any.whl -
Subject digest:
26811086e6701cfb09b5f31480580993beca36364112b29ea62960b28329c187 - Sigstore transparency entry: 2766045970
- Sigstore integration time:
-
Permalink:
genome-spy/genome-spy-python@37eaf35f245c293e8e36365e6a608e03458a4c87 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/genome-spy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@37eaf35f245c293e8e36365e6a608e03458a4c87 -
Trigger Event:
release
-
Statement type: