Scanpy is a Python-based computational framework designed for the analysis of single-cell RNA sequencing (scRNA-seq) data. Built around the AnnData data structure, it provides efficient, scalable implementations of core algorithms for preprocessing, dimensionality reduction, graph-based clustering, and the identification of marker genes across large cell atlases.
Glossary
Scanpy

What is Scanpy?
Scanpy is a scalable, open-source Python toolkit for analyzing single-cell gene expression data, providing end-to-end workflows from preprocessing to visualization and trajectory inference.
The toolkit supports advanced analyses including pseudotime and trajectory inference via partition-based graph abstraction (PAGA), RNA velocity estimation, and data integration for batch effect correction. Its modular architecture and interoperability with the broader Python scientific ecosystem make it a foundational component in modern single-cell bioinformatics pipelines.
Key Features of Scanpy
Scanpy is a scalable Python-based toolkit for analyzing single-cell gene expression data. Built on the AnnData data structure, it provides a comprehensive framework for preprocessing, clustering, and trajectory inference.
Preprocessing & Quality Control
A robust pipeline for cleaning and normalizing raw count matrices. Scanpy provides highly optimized functions for:
- Filtering low-quality cells based on total counts, gene counts, and mitochondrial read fraction
- Normalization to library size with log-transformation
- Highly Variable Gene (HVG) selection to identify informative features
- Regression of technical covariates and cell cycle effects
- Scaling to unit variance for downstream dimensionality reduction
Dimensionality Reduction & Visualization
Tools to embed high-dimensional single-cell data into interpretable 2D spaces. Scanpy wraps efficient implementations of:
- PCA for linear dimensionality reduction on HVGs
- t-SNE for non-linear embedding preserving local structure
- UMAP for fast, scalable manifold learning that preserves global structure
- Diffusion maps for trajectory-aware embeddings
- Built-in plotting functions with automatic coloring by gene expression or metadata
Graph-Based Clustering
Unsupervised cell-type discovery using community detection on k-nearest neighbor graphs. The workflow includes:
- Construction of a neighborhood graph in PCA space
- Application of the Leiden algorithm for modularity optimization
- Resolution parameter tuning to control cluster granularity
- PAGA (Partition-based Graph Abstraction) for visualizing cluster connectivity at multiple resolutions
- Differential expression testing to identify cluster-specific marker genes
Trajectory Inference & Pseudotime
Reconstruction of dynamic biological processes from static snapshot data. Scanpy integrates:
- Diffusion Pseudotime (DPT) for ordering cells along branching trajectories
- RNA Velocity analysis using spliced/unspliced read ratios to predict future cell states
- PAGA for abstracting the connectivity structure of complex differentiation hierarchies
- Visualization of gene expression trends along pseudotime with heatmaps and scatter plots
Data Integration & Batch Correction
Methods to align multiple datasets while preserving biological variation. Scanpy supports:
- BBKNN for batch-aware neighborhood graph construction
- Harmony integration via external wrapper
- scVI probabilistic modeling for latent variable correction
- Combat for location-scale adjustment of batch effects
- Visualization of integrated embeddings colored by batch and cell type to assess mixing quality
Frequently Asked Questions
Direct answers to the most common technical questions about Scanpy's architecture, performance characteristics, and analytical capabilities for single-cell genomics workflows.
Scanpy is a scalable Python-based toolkit for analyzing single-cell gene expression data built on the AnnData data structure. It works by providing a modular pipeline of functions that operate on a central AnnData object—a specialized matrix container storing the count matrix in adata.X, cell metadata in adata.obs, and gene annotations in adata.var. The toolkit implements over 200 functions spanning preprocessing (filtering, normalization, log-transformation), dimensionality reduction (PCA, t-SNE, UMAP), graph-based clustering (Louvain, Leiden), differential expression testing, and trajectory inference. Scanpy's architecture leverages sparse matrix operations and out-of-core computation to handle datasets exceeding one million cells on standard workstations. Its tight integration with the broader Python scientific ecosystem—NumPy, SciPy, pandas, scikit-learn—enables seamless interoperability with machine learning libraries and custom analysis extensions.
Scanpy vs. Seurat: Python and R Toolkits Compared
A technical comparison of the two dominant open-source frameworks for single-cell RNA-seq data analysis, highlighting language ecosystems, data structures, and analytical capabilities.
| Feature | Scanpy | Seurat |
|---|---|---|
Primary Language | Python | R |
Core Data Structure | AnnData | SeuratObject |
Dimensionality Reduction | PCA, t-SNE, UMAP | PCA, t-SNE, UMAP |
Graph-Based Clustering | ||
Louvain Clustering | ||
Leiden Clustering | ||
RNA Velocity | ||
Trajectory Inference (PAGA) | ||
Data Integration (Harmony/CCA) | ||
Spatial Transcriptomics Support | ||
Multimodal Integration (CITE-seq) | ||
Reference-Based Label Transfer | ||
GPU Acceleration | ||
Out-of-Core Processing |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Scanpy is the central hub of the Python single-cell ecosystem. Master these interconnected concepts to build robust, scalable analysis pipelines.
Graph-Based Clustering: Louvain & Leiden
Scanpy identifies cell populations by constructing a k-nearest neighbor (KNN) graph and applying community detection. The Leiden algorithm is the modern default, offering guaranteed well-connected communities.
sc.pp.neighbors(): Builds the KNN graph in PCA space.sc.tl.leiden(): Partitions cells into clusters at a resolution parameter.- Resolution: A tunable parameter controlling cluster granularity (higher = more clusters).
- Modularity: Leiden optimizes the Constant Potts Model, which is resolution-free and mathematically superior to Louvain's modularity.
Trajectory Inference: PAGA & DPT
Scanpy reconstructs developmental lineages without requiring a starting cell. PAGA (Partition-based Graph Abstraction) models connectivity between clusters, while Diffusion Pseudotime (DPT) orders individual cells along a continuum.
sc.tl.paga(): Generates a coarse-grained graph of cluster relationships.sc.tl.dpt(): Computes pseudotime from a user-defined root cell.- RNA Velocity: Use
scvelo(a sister package) to predict future cell states from spliced/unspliced ratios. - Diffusion Maps: The underlying manifold learning technique that preserves differentiation trajectories in low-dimensional space.
Data Integration: Combatting Batch Effects
Scanpy's sc.external module wraps integration tools to align datasets from different experiments. BBKNN (batch-balanced KNN) is a lightweight graph-based method, while Harmony and Scanorama offer alternative algorithmic approaches.
sc.external.pp.bbknn(): Corrects the neighborhood graph directly.- scVI: A deep generative model (via
scvi-tools) that learns a latent representation of batch-corrected data. - Ingest: Projects labels from a reference onto query data using a shared embedding.
- Integration is critical before clustering to ensure biological variation, not technical artifacts, drives cell grouping.
Differential Expression: Rank vs. Wilcoxon
Scanpy identifies marker genes that define clusters using statistical tests designed for sparse, zero-inflated data. Wilcoxon rank-sum is the default non-parametric test, while t-test and logistic regression offer alternatives.
sc.tl.rank_genes_groups(): The primary function for computing differentially expressed genes per cluster.- Log-fold change: The effect size metric indicating expression magnitude difference.
- Adjusted p-value: Bonferroni or Benjamini-Hochberg correction for multiple testing.
- Results are stored in
.uns['rank_genes_groups']and visualized withsc.pl.rank_genes_groups()dotplots or heatmaps.
Visualization: UMAP & Embeddings
Scanpy renders publication-quality figures directly from AnnData objects. UMAP is the standard for visualizing cell clusters, while t-SNE and Force-directed graphs provide alternative layouts.
sc.tl.umap(): Computes the UMAP embedding from the neighborhood graph.sc.pl.umap(): Plots cells colored by cluster, gene expression, or metadata.- Dotplots: Show the percentage of expressing cells and mean expression per cluster.
- Heatmaps: Display the expression matrix of top marker genes across groups.
- Violin plots: Visualize the full distribution of gene expression per cluster.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us