sshash
Python bindings for sshash-rs — a compressed dictionary for DNA k-mers based on Sparse and Skew Hashing.
sshash stores a set of k-mers (strings of length k over {A, C, G, T}) compactly using minimal perfect hashing and succinct data structures (Elias-Fano, BitFieldVec), and supports fast individual and streaming lookups. It is the k-mer index underlying the piscem read mapper.
Installation
pip install sshash
Index compatibility
Version 0.5 is built on sshash-rs 0.8, which changed the index format (index
format 6.0, MPHF container 3.0). Indexes built with sshash 0.4 or earlier must
be rebuilt; loading one fails with a "must be rebuilt" error. Indexes are
always canonical: a k-mer and its reverse complement share one entry
(BuildConfig.canonical is deprecated and ignored).
Building a large index (2^24 minimizers or more) writes temporary files, 16
bytes per minimizer, to BuildConfig.tmp_dir (default sshash_tmp in the
current directory); point it at a scratch disk if needed.
Building an index
From a FASTA/FASTQ file
import sshash
config = sshash.BuildConfig(k=31, m=19)
config.threads = 8 # parallel build (0 = all cores)
config.tmp_dir = "/scratch/tmp" # temporary files for large builds
config.verbose = False
dict = config.build_from_file("sequences.fa.gz")
dict.save("my_index")
From a list of sequences in memory
config = sshash.BuildConfig(k=31, m=19)
sequences = ["ACGTACGTACGTACGTACGTACGTACGTACG",
"TTGCAACCGTTAGCAACGTACGTACGTACGT"]
dict = config.build(sequences)
From a Cuttlefish .cf_seg file
When sequences come from Cuttlefish, build_from_cf_seg also returns a mapping from sshash string IDs back to the original Cuttlefish node IDs:
config = sshash.BuildConfig(k=31, m=19)
dict, segment_ids = config.build_from_cf_seg("unitigs.cf_seg")
# segment_ids[i] is the Cuttlefish node ID for sshash string_id i
Loading and saving
# Save to disk (writes <prefix>.ssi and <prefix>.ssi.mphf)
dict.save("my_index")
# Load from disk
dict = sshash.Dictionary.load("my_index")
Querying
Single k-mer lookup
# Returns a Hit object, or None if not found
hit = dict.query("ACGTACGTACGTACGTACGTACGTACGTACG")
if hit is not None:
print(hit.kmer_id) # global k-mer ID
print(hit.string_id) # unitig containing this k-mer
print(hit.kmer_id_in_string) # position within that unitig
print(hit.orientation) # +1 forward, -1 reverse complement
# Just the k-mer ID (faster if location info isn't needed)
kmer_id = dict.lookup("ACGTACGTACGTACGTACGTACGTACGTACG") # None if absent
# Membership test
present = dict.contains("ACGTACGTACGTACGTACGTACGTACGTACG")
By default, a query on a non-canonical (strand-specific) index falls back to the
reverse complement, so the reverse complement of an indexed k-mer is still found
(reported with orientation == -1). Pass forward_only=True for a strand-specific
query that does not perform this fallback:
# Non-canonical index: only match the k-mer in its given orientation
hit = dict.query("ACGTACGTACGTACGTACGTACGTACGTACG", forward_only=True)
kmer_id = dict.lookup("ACGTACGTACGTACGTACGTACGTACGTACG", forward_only=True)
present = dict.contains("ACGTACGTACGTACGTACGTACGTACGTACG", forward_only=True)
forward_only is ignored for canonical indexes, where both strands are inherently
equivalent.
Streaming queries over a sequence
The streaming engine maintains minimizer state across consecutive k-mers, avoiding redundant MPHF lookups for adjacent positions. This is significantly faster than calling query in a loop when processing full reads or contigs.
engine = dict.streaming_query()
# Query all k-mers in a sequence at once (returns list)
hits = engine.query_sequence("ACGTACGTACGTACGTACGTACGTACGTACGTACGT")
for hit in hits:
if hit is not None:
print(hit.kmer_id, hit.string_id)
# Lazy iterator (memory-efficient for long sequences)
for hit in engine.iter_sequence(b"ACGTACGT..."):
if hit is not None:
print(hit.kmer_id)
# Efficiency statistics
print(engine.num_searches) # full MPHF lookups performed
print(engine.num_extensions) # k-mers resolved by sliding-window extension
Index properties
print(dict.k) # k-mer length
print(dict.m) # minimizer length
print(dict.canonical) # canonical mode flag
print(dict.num_strings) # number of unitigs
print(dict.num_bits) # total index size in bits
BuildConfig options
| Property | Default | Description |
|---|---|---|
canonical |
False |
Map each k-mer and its reverse complement to the same entry |
threads |
0 |
Worker threads during build (0 = all available cores) |
ram_limit_gib |
8 |
RAM budget (GiB) before switching to external sort |
seed |
internal | Seed for internal hash functions |
verbose |
True |
Print progress during building |
tmp_dir |
"sshash_tmp" |
Directory for temporary files during external sort |
k and m are set at construction time and cannot be changed afterwards.
References
- Giulio Ermanno Pibiri. "Sparse and Skew Hashing of K-Mers." Bioinformatics, 2022.
- Giulio Ermanno Pibiri and Rob Patro. "Optimizing sparse and skew hashing: faster k-mer dictionaries." bioRxiv, 2026.
License
BSD 3-Clause
Metadata
Release files for sshash 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sshash-0.5.0.tar.gz | 134.6 kB | With provenance | Details for sshash-0.5.0.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sshash-0.5.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ x86-64 | Details for sshash-0.5.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| sshash-0.5.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ ARM64 | Details for sshash-0.5.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
| sshash-0.5.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl | CPython 3.8 | abi3 | macOS 10.12+ x86-64, macOS 10.12+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64 | Details for sshash-0.5.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
Total release size: 10.3 MB
Release files / sshash-0.5.0.tar.gz
| Download URL | sshash-0.5.0.tar.gz |
|---|---|
| Size | 134.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32f0648ea789d6df03e57c33850091a9ec8f6279852dac1e18f74cf3f5593616
|
|
BLAKE2b-256 checksum How to use checksums |
83d8683fced30a0970e6b0d573b2383bf8ee23d4500ace2ea39cf3dda141c853
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 19, 2026.
Transparency logRelease files / sshash-0.5.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | sshash-0.5.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c476790b44d077b3ffa2429948f4e122320e8e84513ca7affdad17735224d78f
|
|
BLAKE2b-256 checksum How to use checksums |
99cb02b22447adbe3f38ac2c101652dfde7cd98390e0191e8e5ed59b6d5fe4a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 19, 2026.
Transparency logRelease files / sshash-0.5.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | sshash-0.5.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 2.8 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
f963fa490d26bdc7bf58d7fbcc5d4413d303bb7c27b1e8703bca3ace31cea74c
|
|
BLAKE2b-256 checksum How to use checksums |
dacb2db163f0d8159d2f310a5ffb9898a0fc43427112f0e89cb4a6087ad080db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 19, 2026.
Transparency logRelease files / sshash-0.5.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | sshash-0.5.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.8 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
cc105110955cfc4a1f4694e3e5b5c2dd5f9244a09b9ed55c6025155a63a42669
|
|
BLAKE2b-256 checksum How to use checksums |
a68d016f9eec8c8f1f1dbc3b9cc7ff14e470a5c55cd3f7f0ff85b2943d4434f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 19, 2026.
Transparency logSecurity for sshash 0.5.0
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
All 4 files in this release have been uploaded with provenance metadata.
Attestation for sshash-0.5.0.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 Oct 19, 2026.
Transparency logA 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.