Skip to main content

Standalone utilities for working with pose data from SLEAP and other tools.

Project description

sleap-io

CI codecov Release PyPI PyPI - Python Version

A standalone Python library and CLI for working with animal pose tracking data. Read, write, convert, and manipulate pose data across formats with minimal dependencies.

Complements the core SLEAP package but does not include labeling, training, or inference.

Documentation | Examples | CLI Reference

Features

  • Multi-format I/O -- Read and write SLEAP, NWB, COCO, DeepLabCut, Ultralytics YOLO, JABS, Label Studio, CSV, Analysis HDF5, AlphaTracker, and LEAP formats
  • CLI tools -- Inspect, convert, render, and transform data from the command line (sio show, sio convert, sio render, sio transform)
  • Rendering -- Produce publication-quality videos and images with pose overlays, customizable colors, markers, and presets
  • Transforms -- Crop, scale, rotate, pad, and flip videos with automatic coordinate adjustment
  • Merging -- Combine annotations from multiple sources with flexible matching strategies
  • Codecs -- Convert to/from NumPy arrays, DataFrames (pandas/polars), and dictionaries
  • Video I/O -- Read any video format via pluggable backends (FFMPEG, OpenCV, PyAV) with a NumPy-like interface
  • Lazy loading -- Load large SLP files up to 90x faster by deferring object creation
  • Remote URLs -- Load .slp files directly from https://, s3://, gs://, and az:// URLs with lazy range-based reads and optional persistent caching
  • Dataset splits -- Create train/val/test splits and export to formats like Ultralytics YOLO

Installation

Quick start (no install needed)

Run CLI commands instantly with uvx:

uvx sleap-io show labels.slp
uvx sleap-io convert -i labels.slp -o labels.nwb

Install as CLI tool

uv tool install "sleap-io[all]"
sio show labels.slp

Install as Python library

pip install "sleap-io[all]"
# or: uv add "sleap-io[all]"
# or: conda install -c conda-forge sleap-io

From source

pip install "sleap-io[all] @ git+https://github.com/talmolab/sleap-io.git@main"

Optional extras

Video support works out of the box via imageio-ffmpeg. Optional extras provide faster backends and additional format support:

Extra Purpose
opencv Faster video backend
pyav Alternative video backend
mat LEAP .mat file support
polars Fast DataFrame operations
all All of the above

Development

git clone https://github.com/talmolab/sleap-io.git && cd sleap-io
uv sync --all-extras

See CONTRIBUTING.md for more details.

Usage

CLI

# Inspect a labels file
sio show labels.slp

# Convert between formats
sio convert -i labels.slp -o labels.nwb

# Render video with pose overlays
sio render -i predictions.slp -o output.mp4

# Transform (scale, crop, rotate) with coordinate adjustment
sio transform labels.slp --scale 0.5 -o scaled.slp

Python

Load and convert between formats

import sleap_io as sio

labels = sio.load_file("predictions.slp")
labels.save("predictions.nwb")

Format is auto-detected from the extension. See supported formats.

Convert to NumPy arrays

labels = sio.load_file("predictions.slp")

trx = labels.numpy()  # (n_frames, n_tracks, n_nodes, 2)
trx_with_scores = labels.numpy(return_confidence=True)  # (n_frames, n_tracks, n_nodes, 3)

Create labels from scratch

import sleap_io as sio
import numpy as np

skeleton = sio.Skeleton(
    nodes=["head", "thorax", "abdomen"],
    edges=[("head", "thorax"), ("thorax", "abdomen")]
)

instance = sio.Instance.from_numpy(
    points=np.array([[10.2, 20.4], [5.8, 15.1], [0.3, 10.6]]),
    skeleton=skeleton
)

video = sio.load_video("test.mp4")
lf = sio.LabeledFrame(video=video, frame_idx=0, instances=[instance])
labels = sio.Labels(videos=[video], skeletons=[skeleton], labeled_frames=[lf])
labels.save("labels.slp")

Render poses

labels = sio.load_file("predictions.slp")
labels.render("output.mp4")                      # Full video
labels.render("preview.mp4", preset="preview")   # Fast 0.25x preview
sio.render_image(labels[0], "frame.png")         # Single frame

Merge annotations

base = sio.load_file("manual_annotations.slp")
predictions = sio.load_file("predictions.slp")
base.merge(predictions)
base.save("merged.slp")

Create training splits

labels = sio.load_file("labels.slp")
labels.make_training_splits(n_train=0.8, n_val=0.1, n_test=0.1, save_dir="splits/", seed=42)

See the Examples page for more recipes including NWB export, video re-encoding, skeleton replacement, path fixing, and YOLO/COCO export.

Support

For technical inquiries, please open an Issue.

For general SLEAP usage, see sleap.ai.

License

BSD 3-Clause License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sleap_io-0.9.0.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sleap_io-0.9.0-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file sleap_io-0.9.0.tar.gz.

File metadata

  • Download URL: sleap_io-0.9.0.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sleap_io-0.9.0.tar.gz
Algorithm Hash digest
SHA256 ca66f64a9c8a694bd612bd559d10e73261c6e79d3213a838ddd4ca18644887c5
MD5 446abcc8251832c0c678ce3ff7c0af4f
BLAKE2b-256 484e81c41cb345d5c2a8f34b1d84c1920708f0f3025a23c2c6c8a0ec13ee21fe

See more details on using hashes here.

File details

Details for the file sleap_io-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: sleap_io-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sleap_io-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b88af2b9bcdde096cd1ff99dbc1359ca5a480dfe82501d44e5cef911fa128895
MD5 e31dca2805d4526fa1b18f7054968929
BLAKE2b-256 e639b5b8fa64382e25bcc7f463d8be90a1636ca57a02519304c5599b021a3147

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page