Yet Another Sequence Analytics Toolkit - A modern Python library for sequence analysis with polars
Project description
yasqat
Yet Another Sequence Analytics Toolkit
A modern Python library for categorical sequence analysis, built on polars. Designed for social-science and life-course research — labour-market trajectories, health pathways, educational histories, and similar domains.
Inspired by TraMineR (R) and TanaT (Python).
Features
- Polars-native data structures —
Alphabet,StateSequence,SequencePoolfor fast sequence manipulation. Interval-shaped input is sampled into aStateSequenceviaStateSequence.from_intervals(df, time_points=...). - Distance metrics — Optimal Matching, Hamming, LCS, LCP, RLCP, DTW, SoftDTW, Chi², Euclidean, DHD, TWED, and OM variants (OMloc, OMspell, OMstran, NMS, NMSMST, SVRspell), with convenience length/similarity wrappers for LCS, LCP, and RLCP
- Substitution costs — constant, transition-rate, indels, indelslog, future (chi-squared), features (Gower distance)
- Clustering — PAM (k-medoids) with
.predict(), CLARA, hierarchical (scipy linkage); parallel pairwise distance computation vian_jobs - Cluster quality — silhouette (ASW), Point Biserial, Hubert's Gamma, R², PAM range analysis, distance to center, representative extraction
- Discrepancy analysis — pseudo-ANOVA with permutation tests, multi-factor discrepancy, dissimilarity trees
- Descriptive statistics — entropy, transition rates, complexity, turbulence, spell counts, visited states, modal states (with time granularity), sequence frequencies, log-probabilities, subsequence counts (with state filtering and log-transform)
- Normative indicators — volatility, precarity, insecurity, degradation, badness, integration (per-state), proportion positive
- Subsequence mining — frequent subsequence discovery with support thresholds and minimum length, returned as polars DataFrames
- Plot-library agnostic — every method returns a polars
DataFrame, so users can plot with their tool of choice (matplotlib, altair, observable, …).Alphabet.colorsis exposed for consistent palette use. - Filtering — length, time, state, and starts-with sequence filtering
- Data I/O — CSV, Parquet, and DataFrame loading (Hive/Spark/Arrow interop) with automatic type inference
- Synthetic data — Markov-chain and financial trajectory generators
Installation
pip install yasqat
Quick start
from yasqat.io import load_csv
# Load sequences from CSV (also: load_dataframe, load_parquet)
pool = load_csv("trajectories.csv", id_col="id", time_col="time", state_col="state")
# Compute pairwise distances and cluster
dm = pool.compute_distances(method="om", indel=1.0, n_jobs=4)
from yasqat.clustering import pam_clustering
result = pam_clustering(dm, n_clusters=4)
# Descriptive statistics
from yasqat.statistics import longitudinal_entropy, turbulence
longitudinal_entropy(pool)
turbulence(pool)
# Plot with your library of choice — yasqat methods return polars DataFrames
state_distribution = pool.to_state_sequence().state_per_sequence(proportion=True)
# Hand `state_distribution` to matplotlib, altair, etc.
Development
# Clone and install with dev dependencies
git clone https://github.com/rexarski/yasqat.git
cd yasqat
uv venv && source .venv/bin/activate # or activate.fish
uv pip install -e ".[dev]"
# Run tests
uv run pytest
# Lint and format
uv run ruff check src/ tests/
uv run ruff format src/ tests/
# Type check
uv run mypy src/yasqat/
Project conventions
Development guidance lives in CLAUDE.md. This repo follows
Matt Pocock's agent-skills setup:
- Issues are tracked in-repo as markdown under
.scratch/(single source of truth) — see.scratch/README.mdfor the board. - Agent configuration (issue tracker, triage labels, domain docs) lives in
docs/agents/. - Architecture decisions are recorded as ADRs in
docs/adr/.
License
MIT License — see LICENSE for details.
Acknowledgments
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
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 yasqat-0.4.1.tar.gz.
File metadata
- Download URL: yasqat-0.4.1.tar.gz
- Upload date:
- Size: 103.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0169d034a7ba62482218062ed82ab790cc325c6e9cf9867a352cad01de669a90
|
|
| MD5 |
d043aa399ea8642a3b5a7e4aa3b8f5e0
|
|
| BLAKE2b-256 |
2b7e4ab780d26ff8d554c00e7ff351d2018b5b12033ab0f7241dd531a72b34d1
|
File details
Details for the file yasqat-0.4.1-py3-none-any.whl.
File metadata
- Download URL: yasqat-0.4.1-py3-none-any.whl
- Upload date:
- Size: 85.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14a76b6c112aa06d97d1acd0f1e651fc52442f916f8050d57873658a1d7c2b86
|
|
| MD5 |
35045dcb7bd7d04d5a5b4afdca93aff2
|
|
| BLAKE2b-256 |
494b56fbaebcb00c2b03c35309b8f9b718bb52ff4688b39602a2ae858835dfa3
|