Install & Compatibility
Where this runs
tested against v0.9.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.7MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
get_alignments
✓ from spacy_alignments import get_alignments
✗ import spacy_alignments as tokenizations
get_charmap
✓ from spacy_alignments import get_charmap
get_original_spans
✓ from spacy_alignments import get_original_spans
The `get_alignments` function is the core of the library, providing bidirectional mapping between two sequences of tokens that may have undergone different tokenization or normalization processes.
import spacy_alignments as tokenizations
# Example from spacy-alignments README/PyPI
tokens_a = ["å", "BC"]
tokens_b = ["abc"] # the accent is dropped (å -> a) and the letters are lowercased(BC -> bc)
# Get alignment mappings for two different tokenizations
a2b, b2a = tokenizations.get_alignments(tokens_a, tokens_b)
print(f"Alignment from tokens_a to tokens_b: {a2b}")
print(f"Alignment from tokens_b to tokens_a: {b2a}")
Debug
Known issues
breakingVersion 0.9.0 dropped support for Python 3.6.fixUpgrade to Python 3.9 or newer. The current version (0.9.2) supports Python >=3.9, <3.14.
affects: >=0.9.0
gotchaInstallation may require Rust compiler if pre-built binary wheels are not available for your platform and Python version.fixIf `pip install spacy-alignments` fails with build errors, install Rust by following instructions on `rustup.rs` and ensure `cargo` is in your system's PATH.
affects: All versions
gotchaWhen using `spacy-transformers` v1.2 or newer, the alignment between spaCy tokens and transformer tokens for 'fast tokenizers' may differ from previous versions. This is because `spacy-transformers` now uses exact alignment from the underlying tokenizers instead of `spacy-alignments`'s heuristic method.fixBe aware of potential subtle changes in token alignments when upgrading `spacy-transformers`. Verify your downstream tasks if they rely on specific alignment behavior. This primarily impacts transformer pipelines within spaCy rather than direct `spacy-alignments` usage.
affects: spacy-transformers >=1.2
Upgrade
Version history
0.9.2latest on PyPI · released Jun 3, 2025
Audit
Dependencies
spacyoptionalDesigned to align tokenizations for spaCy and transformers, implicitly requiring spaCy for most use cases.
rustoptionalRequired to build the package from source if no pre-compiled binary wheels are available for your platform and Python version.