Skip to main content

polars-list-math

polars-list-math is a Python/Rust package with list, JSON, and URL expression helpers for Polars.

Release notes and upgrade guidance are recorded in CHANGELOG.md.

Import the package once to register extra methods on Expr.list and Expr.str:

import polars as pl
import polars_list_math  # noqa: F401

For type-checked code, import the top-level expression helpers described below.

Install

pip install polars-list-math
# or
uv add polars-list-math

Requires Python 3.12+ and polars>=1.39.3.

Methods

Method Result Docs
Expr.list.zip(...) Zip lists into list[struct] Polars proposal
Expr.list.combinations(...) Pair items in one list, optionally skipping self-pairs Combinations
Expr.list.combinations_to(...) Pair each item with each item from another list Combinations
Expr.list.similarity(...) Weighted similarity between two lists Similarity
Expr.list.mean_similarity(...) Mean similarity inside a nested-list row Similarity
Expr.list.mean_similarity_to(...) Mean similarity to reference nested lists Similarity
Expr.str.json_object_items(...) Convert a JSON object to list[struct[key, value]] JSON object items
Expr.str.json_array_values(...) Convert a JSON array to list[str] JSON array values

Top-level expression helpers provide the statically typed API for Pyright, Pylance, and other type checkers:

Function Result Docs
list_zip(...) Zip lists into list[struct] Examples
list_combinations(...) Pair items in one list Combinations
list_combinations_to(...) Pair items from two lists Combinations
expected_value_of_game(...) Expected value of a sequential game Expected value of a game
list_similarity(...) Weighted similarity between two lists Similarity
list_mean_similarity(...) Mean similarity inside nested lists Similarity
list_mean_similarity_to(...) Mean similarity to reference nested lists Similarity
json_object_items(expr, strict=False) Convert a JSON object to list[struct[key, value]] JSON object items
json_array_values(expr, strict=False) Convert a JSON array to list[str] JSON array values
url_query_encode(expr, doseq=False) Encode a Struct or key/value list as a URL query string URL query encoding
url_build(...) Assemble a URL from optional component expressions URL building
dfs_to_lazy_df(...) Expose DataFrame batches as a pushdown-aware LazyFrame source Examples

The Python helper py_list_similarity(...) computes weighted similarity for plain Python sequences.

Typed schemas and projections are available from polars_list_math.typed_polars; see the typed Polars guide.

The Expr.list and Expr.str methods are registered dynamically and remain available as convenient runtime syntax. Python type checkers cannot safely augment Polars' own namespace classes from another installed package, so use the equivalent top-level functions in code checked by Pylance or Pyright.

If a future Polars release ships native methods with the same names, this package leaves the native implementation untouched.

Quick Examples

from polars_list_math import (
    list_combinations,
    list_mean_similarity,
    list_similarity,
    list_zip,
)

df = pl.DataFrame(
    {
        "a": [[1, 2, 3]],
        "b": [[2, 1, 3]],
        "groups": [[[1, 2, 3], [1, 2, 3], [4, 5, 6]]],
    }
)

df.with_columns(
    list_similarity("a", "b").alias("similarity"),
    list_mean_similarity("groups").alias("mean_similarity"),
    list_combinations("a").alias("pairs"),
    list_zip("a", "b", fields=["a", "b"]).alias("zipped"),
)

Convert JSON strings to nested Polars values. String values stay strings, JSON null stays null, and other values become compact JSON strings. Invalid JSON returns null by default; pass strict=True to raise instead.

from polars_list_math import json_array_values, json_object_items

json_df = pl.DataFrame(
    {
        "object": ['{"name":"Ada","active":true,"note":null}'],
        "array": ['["python",42,true,null]'],
    }
)

json_df.select(
    json_object_items("object").alias("items"),
    json_array_values("array").alias("values"),
)

Encode query parameters and build URLs from expressions:

from polars_list_math import url_build, url_query_encode

pages = pl.DataFrame(
    {
        "host": ["example.com"],
        "path": ["/search"],
        "term": ["rust polars"],
        "page": [2],
    }
)

query = url_query_encode(pl.struct(q=pl.col("term"), page=pl.col("page")))

pages.select(
    url_build(
        scheme=pl.lit("https"),
        netloc="host",
        path="path",
        query=query,
    ).alias("url")
)

More complete, runnable examples are available in the examples directory.

Performance experiments

Reproducible performance experiments live in the performance directory. Each experiment has its own README with the tested scenario, run instructions, environment, and recorded results.

The current dataframe_construction experiment compares construction of 30-column Polars DataFrames from a regular dataclass, a slotted dataclass, and a named tuple, including nested structs and lists.

uv run pytest performance/dataframe_construction -v -s

Development

make install
make develop
make test

Build and check the package locally:

make check-dist

Release steps are in docs/publishing.md.

Metadata

Release files for polars-list-math 0.4.3

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

Source distribution (sdist)

Source distribution for polars-list-math 0.4.3
File Size Uploaded Provenance
polars_list_math-0.4.3.tar.gz 54.5 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for polars-list-math 0.4.3
File
polars_list_math-0.4.3-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
polars_list_math-0.4.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
polars_list_math-0.4.3-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
polars_list_math-0.4.3-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details
polars_list_math-0.4.3-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
polars_list_math-0.4.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
polars_list_math-0.4.3-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
polars_list_math-0.4.3-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details

Total release size: 39.1 MB

Release files / polars_list_math-0.4.3.tar.gz

Download URL polars_list_math-0.4.3.tar.gz
Size 54.5 kB
Tags Source
SHA-256 checksum
How to use checksums
60e89a8fc1070cbaceaba423c686d12cb5b05cfd92b630621a9b9334729ce3e1
BLAKE2b-256 checksum
How to use checksums
a312beb428460e785108694e96f092fe49b6172ca2a384cc6110c57ff61d3b1f
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 Aug 22, 2026.

Transparency log

Release files / polars_list_math-0.4.3-cp313-cp313-win_amd64.whl

Download URL polars_list_math-0.4.3-cp313-cp313-win_amd64.whl
Size 4.9 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
d59e5707bb1e1e2839ccabddddb87371bcff1c0015476fbe76c558d1094f0490
BLAKE2b-256 checksum
How to use checksums
4d39d2b0304b1ea32b1b4e2770e6e27945f181f03c505c25da825cf6289c21f4
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 Aug 22, 2026.

Transparency log

Release files / polars_list_math-0.4.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL polars_list_math-0.4.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 5.3 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ac8a980b0a392e7baaa2ac44b3276d9525ebee0661787ad50708d30f5a572887
BLAKE2b-256 checksum
How to use checksums
0500a4e2ec40808bd3669007d2757183fa4d4f54cb06b8f915eb8310cceb798b
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 Aug 22, 2026.

Transparency log

Release files / polars_list_math-0.4.3-cp313-cp313-macosx_11_0_arm64.whl

Download URL polars_list_math-0.4.3-cp313-cp313-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
86d27369452a14dd87a8b7896a71d8e0dff45bfc9282aa4f588438e278f3e993
BLAKE2b-256 checksum
How to use checksums
a51260f1befb0b149f59f769e28e0f38615243ed81223ea97c51c4ecadd08708
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 Aug 22, 2026.

Transparency log

Release files / polars_list_math-0.4.3-cp313-cp313-macosx_10_12_x86_64.whl

Download URL polars_list_math-0.4.3-cp313-cp313-macosx_10_12_x86_64.whl
Size 4.8 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
32fd5e3b82330dc2e79c266f37d90f5916008ffb2e35d3da4537e031dd9a15c3
BLAKE2b-256 checksum
How to use checksums
a8d858d7b64bb4c056d0a4c336285afdc25b1d48e40d8a4f564a8f5d74d41ffe
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 Aug 22, 2026.

Transparency log

Release files / polars_list_math-0.4.3-cp312-cp312-win_amd64.whl

Download URL polars_list_math-0.4.3-cp312-cp312-win_amd64.whl
Size 4.9 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
5f639cac94692d5dde049cbe6df732170ff8df593c35c144d0a4d794bf6665d9
BLAKE2b-256 checksum
How to use checksums
03b5e8bac2f86a11f391b9f2a253792e7a2d9a61d39178c23be0be817c66aa43
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 Aug 22, 2026.

Transparency log

Release files / polars_list_math-0.4.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL polars_list_math-0.4.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 5.3 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
10cbc4e998931072283efc7fa29b3c77812f1792ae2dc2a75084f8aaf0ae56e6
BLAKE2b-256 checksum
How to use checksums
c4872e309855625ff3ff070503e52fe59f491ae55a10d4d1c63cb4ce2a5ca92c
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 Aug 22, 2026.

Transparency log

Release files / polars_list_math-0.4.3-cp312-cp312-macosx_11_0_arm64.whl

Download URL polars_list_math-0.4.3-cp312-cp312-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
13fddc129b26dd4ff80681a5d2ad7a4a93848dde29e7487287a0f00d4fb60826
BLAKE2b-256 checksum
How to use checksums
1ca8f8e966109909c8eac1d408084107195cba2747e1a431a82466a542376d78
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 Aug 22, 2026.

Transparency log

Release files / polars_list_math-0.4.3-cp312-cp312-macosx_10_12_x86_64.whl

Download URL polars_list_math-0.4.3-cp312-cp312-macosx_10_12_x86_64.whl
Size 4.8 MB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
368287f085829e599f225ec5f8cbffe2f3bd533c91bcde6851c1e684c2943d71
BLAKE2b-256 checksum
How to use checksums
c7e7eed9bdb96bc5c51a225121f27238ae34fd7efe1594edfc0dc3f83599300a
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 Aug 22, 2026.

Transparency log

Security for polars-list-math 0.4.3

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 9 files in this release have been uploaded with provenance metadata.

Select from 9 files

Attestation for polars_list_math-0.4.3.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 Aug 22, 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