Skip to main content

Deacon for Python

Python bindings for Deacon, enabling fast multithreaded DNA sequence filtering for e.g. host pangenome depletion using Python code. These bindings load an index once, allowing subsequent filtering runs with low latency. Deacon's complete functionality is currently only available using the Rust/CLI version of Deacon.

Installation

uv pip install deacon

Quickstart

from deacon import Index

index = Index("panhuman-1.k31w15.idx")
stats = index.filter(
    fastq_path,
    deplete=True,
    rename=True,
    output=fastq_path.replace(".fastq.gz", ".clean.fastq.gz")
)
print(stats["seqs_in"], stats["seqs_out"])

Logging

Deacon logs through Python's standard logging module under the deacon logger. By default only warnings are shown. Enable info messages, such as the summary printed by the CLI, with e.g.:

import logging
logging.basicConfig(level=logging.INFO)

Index()

Load a minimizer index or probabilistic filter from disk. The resulting object may be reused across many filter calls.

index = Index("panhuman-1.k31w15.idx", complexity_threshold=None)

Pass complexity_threshold (0.0–1.0, e.g. 0.9) to discard low-complexity index minimizers once at load using kdust; the filtered set is then reused across all filter calls. Not supported for bff (binary fuse filter) indexes.

path is positional-only and accepts a string or path-like object. complexity_threshold is keyword-only.

Index.fetch()

Download a prebuilt index, then load and return it (a static method, so Index.fetch(...) returns an Index). output is the local path to save to; when omitted it defaults to "{name}.k{k}w{w}.idx" in the working directory. If a file already exists at that path it is loaded without downloading; pass force=True to download and replace it.

index = Index.fetch(
    name="panhuman-1",
    k=31,
    w=15,
    output=None,
    force=False,
    complexity_threshold=None,
)

All fetch() arguments are keyword-only.

Index.info()

index.info() returns a dict of index metadata:

Key Meaning
k k-mer length
w minimizer window size
format exact-u64, exact-u128, or bff (binary fuse filter)
count number of minimizers/keys represented by the index

Index.filter()

Filter FASTA, FASTQ, or CBQ input against the index and return a dict of summary statistics. FASTA/FASTQ compression (.gz, .zst, or .xz) is detected automatically. A .cbq output writes CBQ; .cba writes quality-free CBQ. The Python GIL is released while filtering, so calls benefit from multithreading. Refer to the main Deacon readme for more detailed usage examples.

def filter(
    input,                   # positional-only FASTA, FASTQ, or CBQ path
    /,
    *,                       # every remaining argument is keyword-only
    input2=None,             # second FASTA/FASTQ mate
    interleaved=False,       # treat input as interleaved pairs (cannot combine with input2)
    check_pairs=False,       # validate paired read names
    deplete=False,           # False = search (keep matches); True = deplete (remove matches)
    rename=False,            # replace read names with sequential integers
    output=None,             # output path; None writes FASTA/FASTQ to stdout
    output2=None,            # second output path for paired reads
    summary=None,            # optional JSON summary output path
    abs_threshold=2,         # min absolute minimizer hits to call a match
    rel_threshold=0.01,      # min proportion of minimizers hitting to call a match
    prefix_length=0,         # only use the first N bp of each read (0 = whole read)
    discard_quality=False,   # discard quality scores
    ordered=False,           # preserve input record ordering (deterministic, slightly slower)
    threads=8,               # worker threads for filtering
    compression_level=2,     # output compression level
    compression_threads=0,   # threads for output compression (0 = auto)
    cbq_block_size=16,       # CBQ output block size in MiB (1-1024)
    debug=None,              # optional per-record minimizer hit TSV path
) -> dict

Modes. With deplete=False (the default, search mode) reads that match the index are kept; with deplete=True reads that match are removed (host depletion). A read is a match only when it clears both thresholds: at least abs_threshold minimizer hits and at least rel_threshold of its minimizers hitting the index.

Paired and CBQ input. Use input2= for separate FASTA/FASTQ mates or interleaved=True for an interleaved stream. check_pairs=True validates Illumina CASAVA or /1 and /2 names. CBQ stores pairing internally, so CBQ input cannot be combined with input2 or interleaved; paired CBQ output uses one output and cannot use output2.

Output. When output is None the filtered records are written to stdout. To count without keeping the filtered sequences, pass output="/dev/null". Pass summary= to write the same statistics returned by the call as JSON. For CBQ output, cbq_block_size is a lower bound: a larger input CBQ block size is preserved.

Return value. A dict including the run configuration (version, index, input/input2, output/output2, k, w, abs_threshold, rel_threshold, prefix_length, deplete, rename, ordered, check_pairs) and the results:

Key Meaning
seqs_in, seqs_out, seqs_removed record counts; a pair contributes 2
seqs_out_proportion, seqs_removed_proportion sequence proportions
bp_in, bp_out, bp_removed base-pair counts, covering both mates
bp_out_proportion, bp_removed_proportion base-pair proportions
time wall-clock seconds
seqs_per_second, bp_per_second throughput (filtering only)
seqs_per_second_total, bp_per_second_total throughput (including load/IO)

Metadata

Release files for deacon 0.20.0

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

Source distribution (sdist)

Source distribution for deacon 0.20.0
File Size Uploaded Provenance Actions
deacon-0.20.0.tar.gz 3.2 MB With provenance Details for deacon-0.20.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for deacon 0.20.0
File Interpreter ABI Platform Actions
deacon-0.20.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 abi3 Linux glibc 2.17+ x86-64 Details for deacon-0.20.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
deacon-0.20.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.12 abi3 Linux glibc 2.17+ ARM64 Details for deacon-0.20.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
deacon-0.20.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for deacon-0.20.0-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 12.0 MB

Release files / deacon-0.20.0.tar.gz

Download URL deacon-0.20.0.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
2a0fee4880010d4b650e14377df70077209ae6bc35097509c5e0a081dd063fe1
BLAKE2b-256 checksum
How to use checksums
64be29abcb62f204ba024e37b8344fcdb3443d2b5619e1c7803c4a77b482f76f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 18, 2026.

Transparency log

Release files / deacon-0.20.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL deacon-0.20.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 3.3 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
88c9476bb7285aab0795e958fa07a56f62a4a6d82559af827a4774a05a8cf966
BLAKE2b-256 checksum
How to use checksums
82eb9b7eca74a96ec1297dc58d1371818dd611b809857b576407625c606dbbf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 18, 2026.

Transparency log

Release files / deacon-0.20.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL deacon-0.20.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 3.1 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
9156068c719cb850760702c8dd21747f364f5684892d32440a0c5646e5aaf2f5
BLAKE2b-256 checksum
How to use checksums
b53a0b36b19e5cb68923335140dd18a306e5253c9bd3538a569ca48c60a5476e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 18, 2026.

Transparency log

Release files / deacon-0.20.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL deacon-0.20.0-cp312-abi3-macosx_11_0_arm64.whl
Size 2.4 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a4c83c31a65c50926fe39e317c5a7785143a2aef4f5c3739b3f92bbec2b108ee
BLAKE2b-256 checksum
How to use checksums
64b65057ae846afe16ef7e10b72c13594007dfa832c112c69397bb640ead25c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 18, 2026.

Transparency log

Security for deacon 0.20.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.

Select from 4 files

Attestation for deacon-0.20.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 Nov 18, 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.

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