Skip to main content

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.1

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

Built distributions (wheels)

Table of built distributions (wheels) for lexindex-polars 0.1.1
File
lexindex_polars-0.1.1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
lexindex_polars-0.1.1-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.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details
lexindex_polars-0.1.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
lexindex_polars-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 19.6 MB

Release files / lexindex_polars-0.1.1-cp311-abi3-win_amd64.whl

Download URL lexindex_polars-0.1.1-cp311-abi3-win_amd64.whl
Size 4.1 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
5dfa3ad292537cc294b3792b93163e46eb793b00b59d01709a279e69545d4be6
BLAKE2b-256 checksum
How to use checksums
457c61eb23354c6a184bed882ff3fc0b1a7d9d8ac77c925f0789374db8f9b009
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 24, 2026.

Transparency log

Release files / lexindex_polars-0.1.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL lexindex_polars-0.1.1-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
4801b1063661a9e4fe7e885de4ec9100cbf12dd772a439b16c08e39465ad4461
BLAKE2b-256 checksum
How to use checksums
92fa129f4c1570d03b00fb5e20371b4b3c50f4cff4bd4f2457c99cedda1dbf8c
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 24, 2026.

Transparency log

Release files / lexindex_polars-0.1.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL lexindex_polars-0.1.1-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
2134535ee597d99b29825d4b3ac7a61389161e1b1b53797db8c8ae7fa6b1e407
BLAKE2b-256 checksum
How to use checksums
1f58a42de8ef00172be7f9bbd82e26a1866cee7dd83d0c4a07ebf2b0c6def3a1
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 24, 2026.

Transparency log

Release files / lexindex_polars-0.1.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL lexindex_polars-0.1.1-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
42c1ba1c734cff4b8da099337638d54468d5932d2009a921ca8757aaf5932049
BLAKE2b-256 checksum
How to use checksums
49ade8aa05e9d447406a358db23987e398a860e5b33bdd6f8fcb73019fcf77d4
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 24, 2026.

Transparency log

Release files / lexindex_polars-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl

Download URL lexindex_polars-0.1.1-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
4b6895a829b86a2d02be66b245854acce0b122a3dfd3ec1d6cc61c1751070a84
BLAKE2b-256 checksum
How to use checksums
a70ea8a7f54dad317df5fa01faaea78ce058c2a031ba9d0007b283e3ec748907
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 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

5 release files

0.1.0

5 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