lexindex-polars
A Polars expression plugin over lexindex: map a string column to dense ids from an index built once and stored in a file, and map the ids back to their keys.
pip install lexindex-polars
import lexindex as lx
import polars as pl
import lexindex_polars # noqa: F401 -- the import registers the namespace
lx.DictIndex(sorted(set(catalog))).save("tracks.bdx") # once, offline
df.with_columns(
pl.col("track").lexindex.id("tracks.bdx").alias("track_id"),
)
The expressions are elementwise, so they run in the engine's own threads, inside a lazy plan and under the streaming engine, and hold no GIL. The blob is read once per process and shared by every chunk and thread.
The four expressions
| expression | takes | gives | on a key the index does not hold |
|---|---|---|---|
.lexindex.id(path) |
a string column | UInt64 |
null |
.lexindex.id_unchecked(path) |
a string column | UInt64 |
some id below the key count |
.lexindex.contains(path) |
a string column | Boolean |
false |
.lexindex.key(path) |
an integer column | String |
null |
null in, null out, for all four.
What each index kind answers
An index blob names its own kind, so one expression serves all six and refuses what a kind cannot
do — with a ComputeError naming the kind and the file, not a wrong answer.
| kind | id |
id_unchecked |
contains |
key |
|---|---|---|---|---|
DictIndex |
exact | — | exact | ✅ |
StringIndex |
exact | — | exact | ✅ |
HashedDictIndex |
exact at 0 bits, else 2^-bits |
✅ | same | ✅ |
PerfectHashIndex |
exact | ✅ | exact | ✅ |
CompactHashIndex |
2^-bits |
✅ | 2^-bits |
— |
ClosedHashIndex |
every key gets one | ✅ | — | — |
2^-bits is the rate at which a key the index does not hold is answered as though it did — the
fingerprint width chosen when the index was built. Where the table says —, the expression raises.
Which kind to build is lexindex's own
question: DictIndex when the ids must be the key
order and size matters, HashedDictIndex when they must be the key order and id is the hot path,
CompactHashIndex when only string → id is needed and a rare false positive is acceptable.
lexindex plan keys.txt prices every one of them against your own keys.
Reading the blob
The file named by an expression is read whole on first use and cached for the process, keyed by
path, size and modification time. Rewriting the file replaces that entry, so a later chunk sees the
new index and an earlier one does not: do not rebuild an index a running query is reading.
Nothing stays mapped, and this crate writes no unsafe.
Paths are expanded and made absolute when the expression is built, not when it runs, so a query keeps reading one file even if a symlink is swapped under it.
Versions
The plugin is compiled against polars' own FFI: the wheel names the polars it was built and tested
against (polars>=1.44), and a much older polars will refuse to load it. lexindex itself is a
normal dependency — it is what writes the blobs this reads.
The wheel is abi3 for CPython 3.11 and up, which is what every polars plugin ships. On a
free-threaded interpreter (cp314t) pip will not take an abi3 wheel, so build it from source
there — pip install 'lexindex-polars @ git+https://github.com/ilgrad/lexindex#subdirectory=polars',
which needs a Rust toolchain.
Licence
MIT, the same as lexindex. Issues and discussion live in the lexindex repository.
Release files for lexindex-polars 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| lexindex_polars-0.1.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details |
| lexindex_polars-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| lexindex_polars-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| lexindex_polars-0.1.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
| lexindex_polars-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 19.5 MB
Release files / lexindex_polars-0.1.0-cp311-abi3-win_amd64.whl
| Download URL | lexindex_polars-0.1.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
90695bd87ac1a5e1bc1904fc5e632253e1a151fd9cc37bd1083a98b67b5ad8b6
|
|
BLAKE2b-256 checksum How to use checksums |
b2a0e1b2ea063720c3667d460c6bb19e22707b3c6cc732b944c4fce08e5c7ea1
|
| 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 Sep 22, 2026.
Transparency logRelease files / lexindex_polars-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | lexindex_polars-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e441247dd77435d29623329e3f416e6db3ba72b3d2afc66afdc10e92136c2aab
|
|
BLAKE2b-256 checksum How to use checksums |
78b71c05543215024332f50b98eedcf38e5f6737115b8941d2df8e2892380ec9
|
| 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 Sep 22, 2026.
Transparency logRelease files / lexindex_polars-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | lexindex_polars-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
f5f4556885e7dc3fb56085485e187d3912bbe0901b0efb4a5e8cdac402c590bd
|
|
BLAKE2b-256 checksum How to use checksums |
9dc93ba6d6a5451a23171171686e33e2ad34badc1cc903d32288efc86bf3a22a
|
| 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 Sep 22, 2026.
Transparency logRelease files / lexindex_polars-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | lexindex_polars-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
727fc28eb5daf4e63957b30c72a2892b9de5baef36270a21aedeaf6242f1e51d
|
|
BLAKE2b-256 checksum How to use checksums |
0461722dde2796578ffe21a850cca97f312823e97fa652102a72b73f92f463b3
|
| 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 Sep 22, 2026.
Transparency logRelease files / lexindex_polars-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | lexindex_polars-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 3.9 MB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
65225f2e8a04cf8141c1a1a925170e8b8932cf9991e738daea459ad1fb75c62c
|
|
BLAKE2b-256 checksum How to use checksums |
ff1efeb5fcb522e05685f09e4df1c43724a03cbe908d9ba75ce68263be13933b
|
| 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 Sep 22, 2026.
Transparency log