Skip to main content

Histokit

Histokit is a histopathology whole slide image preprocessing package for Python and command line tool.

Install as a tool

Histokit can be installed as a command line tool directly from this repository using uv. Here is an example:

uv tool update-shell
uv tool install git+https://github.com/davemor/histokit

CLI Interface

❯ histokit --help

 Usage: histokit [OPTIONS] COMMAND [ARGS]...

 histokit — histopathology toolkit CLI.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --install-completion          Install completion for the current shell.      │
│ --show-completion             Show completion for the current shell, to copy │
│                               it or customize the installation.              │
│ --help                        Show this message and exit.                    │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ list     List available built-in pipelines.                                  │
│ plan     Show pipeline stages and resolved parameters.                       │
│ run      Run a pipeline on a dataset and save the resulting PatchSet.        │
│ preview  Preview a pipeline on a single sample with diagnostic images.       │
│ export   Export patch images from a saved PatchSet to label-name             │
│          directories.                                                        │
╰──────────────────────────────────────────────────────────────────────────────╯

histokit list

Show all built-in pipelines that ship with histokit. Each entry shows the import reference and stage count.

histokit list
Available pipelines:

  histokit.pipelines.presets.basic:pipeline  (4 stages)
  histokit.pipelines.presets.research:pipeline  (4 stages)

histokit plan

Inspect a pipeline's stages and see what parameters they use. Use --set to preview overrides without running anything.

# Show default parameters
histokit plan histokit.pipelines.presets.basic:pipeline

# Preview with overrides
histokit plan histokit.pipelines.presets.basic:pipeline --set patch_size=512 --set level=0

histokit run

Run a pipeline on a full dataset and save the combined PatchSet to disk.

# Basic run
histokit run histokit.pipelines.presets.basic:pipeline \
  --index data/icaird/cervical_mini/index.csv \
  --labels data/icaird/cervical_mini/labels.json \
  --output runs/cervical_basic

# With parameter overrides
histokit run histokit.pipelines.presets.basic:pipeline \
  --index data/icaird/cervical_mini/index.csv \
  --labels data/icaird/cervical_mini/labels.json \
  --output runs/cervical_512 \
  --set patch_size=512

# Overwrite a previous run
histokit run histokit.pipelines.presets.basic:pipeline \
  --index data/icaird/cervical_mini/index.csv \
  --labels data/icaird/cervical_mini/labels.json \
  --output runs/cervical_basic \
  --overwrite

histokit preview

Run a pipeline on a single sample and save diagnostic images (thumbnail, patch overlay) to an output directory. Useful for checking pipeline settings before a full run.

# Preview the first sample in the dataset
histokit preview histokit.pipelines.presets.basic:pipeline \
  --index data/icaird/cervical_mini/index.csv \
  --labels data/icaird/cervical_mini/labels.json \
  --output preview/cervical

# Preview a specific sample
histokit preview histokit.pipelines.presets.basic:pipeline \
  --index data/icaird/cervical_mini/index.csv \
  --labels data/icaird/cervical_mini/labels.json \
  --output preview/cervical \
  --sample IC-CX-00001-01

histokit export

Export patch images from a saved PatchSet to label-name subdirectories, compatible with torchvision.datasets.ImageFolder.

histokit export runs/cervical_basic \
  --index data/icaird/cervical_mini/index.csv \
  --labels data/icaird/cervical_mini/labels.json \
  --output patches/cervical_basic

The output directory will contain one folder per label with individual patch PNG files and a provenance.json recording how the export was produced.

Pipeline Stages

Histokit is based around configurable pipelines with the following stages:

  1. Patch Selection
  2. Foreground Identification
  3. Patch Labelling
  4. Patch Filtering
  5. Patch Rendering

Pipelines consume dataset objects that represent a set of slides and, optionally, their annotations. They output a patchset: an object that stores patch coordinates, their labels, and their provenance (the slide they came from, the way they have been processed). The patchset can then be used to generate patch images or an input into a downstream feature extraction model.

Patch Selection

This stage decides how the patches will be sampled from the whole slide images, based on:

  • geometry (level, patch size, stride)
  • strategy (grid, from annotation)
  • sampling (dense, sparse, multiscale)

Foreground Identification

The stage classifies the patches into Foreground and Background. This usually means tissue detection but it might also mean blood and mucus detection.

  • methods (fixed threshold, otsu)
  • resolution (thumbnail vs patch-level)
  • threshold (minimum tissue fraction)

Patch Labelling

Assign labels to the patches derived from annotations. This involves rendering the annotation polygons and converting them to patch labels. This may involve having a default label that everything that is not labelled uses.

Patch Selection

The stage applies selection rules such as:

  • should the background be dropped?
  • should only labelled patches be used?
  • remove unreliable or corrupted patches based on quality

Patch Rendering

The patchset can then be used to export the patch images. The patches can be normalised using stain normalisation.

Data Model

Datasets - represent a set of slide, their annoations, and meta data. Datasets provide the following information:

  • a list of the slides
  • a list of slide annotations (optional)
  • the format to use to load the slides
  • meta data about each slide (multiple slide level labels)

Patchset - an index of the patches on a slide, their labels, provinence, and other meta data.

The patchset is constructed thoughout the different stages, i.e. the different stages add the

Metadata

Release files for histokit 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for histokit 0.0.1
File Size Uploaded Provenance Actions
histokit-0.0.1.tar.gz 29.8 kB With provenance Details for histokit-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for histokit 0.0.1
File Interpreter ABI Platform Actions
histokit-0.0.1-py3-none-any.whl Python 3 none any Details for histokit-0.0.1-py3-none-any.whl

Total release size: 79.2 kB

Release files / histokit-0.0.1.tar.gz

Download URL histokit-0.0.1.tar.gz
Size 29.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0637d22f7afb92fdaa01ffb7b00ed21fb9c0f53104013dbbc5e8fdbe6833cb3b
BLAKE2b-256 checksum
How to use checksums
9ce94ceb3f5f3c7dfa8adbb56c41f52a22677e0f979b057460aaaa0e9836f6a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 14, 2026.

Transparency log

Release files / histokit-0.0.1-py3-none-any.whl

Download URL histokit-0.0.1-py3-none-any.whl
Size 49.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb2ed552361048791ad8297244509920193a257a7c8ef61b79c1348643fd8b40
BLAKE2b-256 checksum
How to use checksums
6e00ba6139c72f0ed656268ad1524e89522bd3f6ad73f1f61ff42ea9a1e33942
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 14, 2026.

Transparency log

Security for histokit 0.0.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for histokit-0.0.1.tar.gz

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 Apr 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files Full provenance

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