annsel
Annsel is a user-friendly library that brings familiar dataframe-style operations to AnnData objects.
It's built on the narwhals compatibility layer for dataframes.
Take a look at the GitHub Projects board for features and future plans: Annsel Features
Getting started
Please refer to the documentation, in particular, the API documentation.
There's also a brief tutorial on how to use all the features of annsel: All of Annsel.
Installation
You need to have Python 3.12 or newer installed on your system. If you don't have
Python installed, we recommend installing uv.
There are several ways to install annsel:
-
Install the most recent release:
With
uv:uv add annsel
With
pip:pip install annsel
-
Install the latest development version:
With
uv:uv add git+https://github.com/srivarra/annsel
With
pip:pip install git+https://github.com/srivarra/annsel.git@main
Examples
annsel comes with a small dataset from Cell X Gene to help you get familiar with the API.
import annsel as an
adata = an.datasets.leukemic_bone_marrow_dataset()
The dataset looks like this:
AnnData object with n_obs × n_vars = 31586 × 458
obs: 'Cluster_ID', 'donor_id', 'Sample_Tag', 'Cell_label', 'is_primary_data', 'organism_ontology_term_id', 'self_reported_ethnicity_ontology_term_id', 'assay_ontology_term_id', 'tissue_ontology_term_id', 'Genotype', 'development_stage_ontology_term_id', 'sex_ontology_term_id', 'disease_ontology_term_id', 'cell_type_ontology_term_id', 'suspension_type', 'tissue_type', 'cell_type', 'assay', 'disease', 'organism', 'sex', 'tissue', 'self_reported_ethnicity', 'development_stage', 'observation_joinid'
var: 'vst.mean', 'vst.variance', 'vst.variance.expected', 'vst.variance.standardized', 'vst.variable', 'feature_is_filtered', 'Unnamed: 0', 'feature_name', 'feature_reference', 'feature_biotype', 'feature_length', 'feature_type'
uns: 'cell_type_ontology_term_id_colors', 'citation', 'default_embedding', 'schema_reference', 'schema_version', 'title'
obsm: 'X_bothumap', 'X_pca', 'X_projected', 'X_projectedmean', 'X_tsneni', 'X_umapni'
Filter
You can filter on obs, var, var_names, obs_names, X and it's layers, as well as obsm and varm matrices as a key-value pair containing the attribute's key name and the predicate to filter on. Currently the column names are numerical indices for obsm and varm matrices.
adata.an.filter(
obs=(
an.col(["Cell_label"]).is_in(["Classical Monocytes", "CD8+CD103+ tissue resident memory T cells"]),
an.col(["sex"]) == "male",
),
var=an.col(["vst.mean"]) >= 3,
obsm={"X_pca": an.col([0]) > 0}, # PC1 values greater than 0
copy=False, # Whether to return a copy of the AnnData object or just a view of it.
)
View of AnnData object with n_obs × n_vars = 736 × 67
obs: 'Cluster_ID', 'donor_id', 'Sample_Tag', 'Cell_label', 'is_primary_data', 'organism_ontology_term_id', 'self_reported_ethnicity_ontology_term_id', 'assay_ontology_term_id', 'tissue_ontology_term_id', 'Genotype', 'development_stage_ontology_term_id', 'sex_ontology_term_id', 'disease_ontology_term_id', 'cell_type_ontology_term_id', 'suspension_type', 'tissue_type', 'cell_type', 'assay', 'disease', 'organism', 'sex', 'tissue', 'self_reported_ethnicity', 'development_stage', 'observation_joinid'
var: 'vst.mean', 'vst.variance', 'vst.variance.expected', 'vst.variance.standardized', 'vst.variable', 'feature_is_filtered', 'Unnamed: 0', 'feature_name', 'feature_reference', 'feature_biotype', 'feature_length', 'feature_type'
uns: 'cell_type_ontology_term_id_colors', 'citation', 'default_embedding', 'schema_reference', 'schema_version', 'title'
obsm: 'X_bothumap', 'X_pca', 'X_projected', 'X_projectedmean', 'X_tsneni', 'X_umapni'
Select
You can select on obs, var, var_names, obs_names, X and it's layers. Selecting returns a new AnnData object. It's useful if you don't need all the columns in obs or var and just want to work with a few.
adata.an.select(
obs=an.col(["Cell_label"]),
var=an.col(["vst.mean", "vst.std"]),
)
Group By
You can group over obs and var columns which returns a generator of objects containing the grouped data and the grouping parameters.
gb_adata_result = adata.an.group_by(
obs=an.col(["Cell_label"]),
var=an.col(["feature_type"]),
copy=False,
)
Here's what the first group looks like:
next(adata.an.group_by(
obs=an.col(["Cell_label"]),
copy=False,
))
GroupByAnnData:
├── Observations:
│ └── Cell_label: Lymphomyeloid prog
├── Variables:
│ └── (all variables)
└── AnnData:
View of AnnData object with n_obs × n_vars = 913 × 458
obs: 'Cluster_ID', 'donor_id', 'Sample_Tag', 'Cell_label', 'is_primary_data', 'organism_ontology_term_id', 'self_reported_ethnicity_ontology_term_id', 'assay_ontology_term_id', 'tissue_ontology_term_id', 'Genotype', 'development_stage_ontology_term_id', 'sex_ontology_term_id', 'disease_ontology_term_id', 'cell_type_ontology_term_id', 'suspension_type', 'tissue_type', 'cell_type', 'assay', 'disease', 'organism', 'sex', 'tissue', 'self_reported_ethnicity', 'development_stage', 'observation_joinid'
var: 'vst.mean', 'vst.variance', 'vst.variance.expected', 'vst.variance.standardized', 'vst.variable', 'feature_is_filtered', 'Unnamed: 0', 'feature_name', 'feature_reference', 'feature_biotype', 'feature_length', 'feature_type'
uns: 'cell_type_ontology_term_id_colors', 'citation', 'default_embedding', 'schema_reference', 'schema_version', 'title'
obsm: 'X_bothumap', 'X_pca', 'X_projected', 'X_projectedmean', 'X_tsneni', 'X_umapni'
Pipe
There's also a small utility method which allows you to chain operations together like in Xarray and Pandas called pipe.
import scanpy as sc
adata.an.pipe(sc.pl.embedding, basis="X_tsneni", color="Cell_label")
Release notes
See the changelog.
Contact
For questions and help requests, you can reach out in the scverse discourse or the discussions tab. If you found a bug, please use the issue tracker.
Citation
Varra, S. R. annsel [Computer software]. https://github.com/srivarra/annsel
Metadata
Release files for annsel 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| annsel-0.1.3.tar.gz | 267.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| annsel-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 284.7 kB
Release files / annsel-0.1.3.tar.gz
| Download URL | annsel-0.1.3.tar.gz |
|---|---|
| Size | 267.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ef0341057f57a93294bec98ab8f4aef83be67ea280389b544ad668b220fbb04
|
|
BLAKE2b-256 checksum How to use checksums |
d259a7ef7cd8038a62660c7d409abcc97ca2885337f867b61d96667dafcfa16c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.
Transparency logRelease files / annsel-0.1.3-py3-none-any.whl
| Download URL | annsel-0.1.3-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
16eb2d520be086f8e9c8e04cf3e75a5f29814d72f602b48166c10af82bc1eb9d
|
|
BLAKE2b-256 checksum How to use checksums |
69213587d7b32dfade1532d9cbb67291cb26f4353c296cadcda6767bd62458d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.
Transparency log