Skip to main content

Sassy Python Bindings

🐍 The python bindings for Sassy

Installation

Pip.

pip install sassy-rs

(as sassy was already taken we chose sassy-rs)

From source. In the root of the repository, run:

maturin develop --features python

You need Maturin for this, see maturin:

Usage

A simple usage is as follows:

import sassy
pattern = b"ATCGATCG"
text = b"GGGGATCGATCGTTTT"
# alphabet: ascii, dna, iupac
searcher = sassy.Searcher("dna")
matches = searcher.search(pattern, text, k=1)
for i, match in enumerate(matches):
    print(f"Match {i+1}:")
    print(f"    Start: {match.text_start}")
    print(f"    End: {match.text_end}")
    print(f"    Cost: {match.cost}")
    print(f"    Strand: {match.strand}")
    print(f"    CIGAR: {match.cigar}")

This finds 3 matches:

Match 1:
    Start: 4
    End: 12
    Cost: 0
    Strand: +
    CIGAR: 8=
Match 2:
    Start: 6
    End: 14
    Cost: 1
    Strand: -
    CIGAR: 6=X=
Match 3:
    Start: 2
    End: 10
    Cost: 1
    Strand: -
    CIGAR: X7=

Further options are sassy.Searcher(alpha=0.5) to allow overhang alignments, sassy.Searcher("dna", rc=False) to disable reverse complements for DNA or IUPAC strings, and sassy.Searcher("dna", max_n_frac=0.1) to drop matches whose aligned text region is more than 10% N bases. Here, max_n_frac is a fraction in [0, 1] where omitting it or using 1.0 disables the filter. searcher.search is the simple function to search one pattern in one text, while searcher.search_many takes multiple patterns and multiple texts and searches each pattern in each text, possibly in multiple threads.

See sassy/example.py for a larger example.

Type Hints

This package ships PEP 561 type stubs (sassy/py.typed + sassy/__init__.pyi) so that type checkers and IDEs can provide autocomplete and type checking out of the box.

The .pyi stubs are auto-generated by the PyPI publishing workflow, and are not stored in git. To manually generate stubs for local testing:

# macOS
RUSTFLAGS="-C link-arg=-undefined -C link-arg=dynamic_lookup" cargo build --features python
cargo run --features python-stubs --bin gen_stubs -- target/debug/libsassy.dylib

# Linux
cargo build --features python
cargo run --features python-stubs --bin gen_stubs -- target/debug/libsassy.so

Once the stubs have been generated, type-checking for the sassy Python library will be enabled. See sassy/example_typed.py for a typed example that exercises all public APIs.

Running the example requires the sassy package be installed in your environment.

To install maturin and the package in an isolated environment, then run the typed example you can use a single uv command:

uv run \
    --with maturin \
    sh -c 'maturin develop && python python/sassy/example_typed.py'

Running type checking on the type exampled requires mypy be installed in your environment.

To install mypy in an isolated environment then run type checking on the typed example you can use a single uv command:

uv run \
    --with mypy \
    sh -c 'mypy python/sassy/example_typed.py'

Troubleshooting

1. I could install sassy-rc but no modules/functions are found.

When creating an issue please include the output of print(dir(sassy)) if you were able to install sassy-rs but no functions/modules were found.

Your output might look like:

['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

Whereas it should look like:

['Match', 'Searcher', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'features']

2. Other sassy issues.

If you were able to install sassy, but have other issues please also add the output of sassy.features().

Metadata

Release files for sassy-rs 0.3.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 sassy-rs 0.3.0
File Size Uploaded
sassy_rs-0.3.0.tar.gz 1.5 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for sassy-rs 0.3.0
File Interpreter ABI Platform
sassy_rs-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
sassy_rs-0.3.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details

Total release size: 2.4 MB

Release files / sassy_rs-0.3.0.tar.gz

Download URL sassy_rs-0.3.0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
91fd35f436e6beaefc7b6d679858095d7ba5f3412ec4fa4815236eeb137c8474
BLAKE2b-256 checksum
How to use checksums
de82c46906ed2e41257059bbd11efe2a0afa2c1a66e75b0c6aea7c341ec3a5e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / sassy_rs-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL sassy_rs-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 481.2 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
12c8968be7c989d9508bab93aa186dbe26c9c96c52a7c37802fa07af1840c387
BLAKE2b-256 checksum
How to use checksums
c7c43f4390aacf2bdc58b44db118303f96c48ac027a6a9605ea89eae2b583cce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / sassy_rs-0.3.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL sassy_rs-0.3.0-cp38-abi3-macosx_11_0_arm64.whl
Size 425.2 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5c6f402315db08fc8494dd510f3b83bd4b544b0a4c2d25cf53057a1f0ba0005d
BLAKE2b-256 checksum
How to use checksums
65ecf2e013812cc95752055ba54b878a052486dc1c8aaa331361b03bfa0bda5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.3.0 This release

3 release files

0.2.6

3 release files

0.2.5

3 release files

0.2.4

3 release files

0.2.3

3 release files

0.2.1

3 release files

0.2.0

3 release files

0.1.10

3 release files

0.1.8

3 release files

0.1.7

6 release files

0.1.6

6 release files

0.1.5

6 release files

0.1.4

6 release files

0.1.3

6 release files

0.1.2

3 release files

0.1.1

4 release files

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