Skip to main content

polars-list-math

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

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

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.

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

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.1
File Size Uploaded Provenance
polars_list_math-0.4.1.tar.gz 50.9 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for polars-list-math 0.4.1
File
polars_list_math-0.4.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
polars_list_math-0.4.1-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.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
polars_list_math-0.4.1-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.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
polars_list_math-0.4.1-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.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
polars_list_math-0.4.1-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details

Total release size: 39.0 MB

Release files / polars_list_math-0.4.1.tar.gz

Download URL polars_list_math-0.4.1.tar.gz
Size 50.9 kB
Tags Source
SHA-256 checksum
How to use checksums
14127fe79e7c0d947f1446352baf316a42da2231707bda95efbbb193224493d8
BLAKE2b-256 checksum
How to use checksums
2de44ecccb0403bbe4b475a32e5a06aa59fa179d0d0b693b50983124297d89e7
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 17, 2026.

Transparency log

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

Download URL polars_list_math-0.4.1-cp313-cp313-win_amd64.whl
Size 4.9 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
2294f1c846cd5043d506afd896990136eac94f10147c78e06b62756c38c1a4cc
BLAKE2b-256 checksum
How to use checksums
72d2e85c7fda601398813e1b8b0a3b276b93b7af04b2ccf5f9c5e22a6300e223
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 17, 2026.

Transparency log

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

Download URL polars_list_math-0.4.1-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
c37f5c94320ecfc1876e8d02739b5cbeeeb79fea98b653da3ecd80dd5733f991
BLAKE2b-256 checksum
How to use checksums
4e660b4db214ba332e2c10d4886ee9bfdc048bb89d9fc666c8a1f2efaf1f6e9c
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 17, 2026.

Transparency log

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

Download URL polars_list_math-0.4.1-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
2d4eefa46e5d16069a0be181e3024b000910423893814878004399631a1464db
BLAKE2b-256 checksum
How to use checksums
5f286d6dd838bcf2cf6f9caca94955e5751cac5e45bce03e6c7201e06202f6da
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 17, 2026.

Transparency log

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

Download URL polars_list_math-0.4.1-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
3b0d9cd400666ec7ab09d30f6ac9782152bce0edc86a782dd5bf2705261e0f2c
BLAKE2b-256 checksum
How to use checksums
e0cae9495b3befb0fa6c3c501e75a712c138a5acd3e71fee34fa8673c175ae88
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 17, 2026.

Transparency log

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

Download URL polars_list_math-0.4.1-cp312-cp312-win_amd64.whl
Size 4.9 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
cfb5b11e8ce5f65996c4399ef70d314bc5ed274cc322cedc690a513ca8dc282e
BLAKE2b-256 checksum
How to use checksums
d8deaecbcd4ddf4bfb3dc04c307a6b6a4e9bf35a8dc7bc84a14d219b9a8ad946
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 17, 2026.

Transparency log

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

Download URL polars_list_math-0.4.1-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
8beddc342bcbc14e0898d25522797f50d5846b4e12556a9d47182ae182d5c986
BLAKE2b-256 checksum
How to use checksums
f349cf9c4d41441ee835c6b83160d91dfbd40a84c3bb422b788af57e48b087cb
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 17, 2026.

Transparency log

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

Download URL polars_list_math-0.4.1-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
be29490c5a95a8ba00644d19ff0e4c7b824829652fe580516adb2007f761ea5a
BLAKE2b-256 checksum
How to use checksums
cd5ea5c12309a858ad56774378a89870034fe08db11e572fdc9bcb7f1311eac4
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 17, 2026.

Transparency log

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

Download URL polars_list_math-0.4.1-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
3434d85ae0f94294cf2b1e71d31f2bdc9128a9576e0fd9c4291533bc198dc4ef
BLAKE2b-256 checksum
How to use checksums
5f81bd05d78b9224ee7815520684d70e96478fce821ef74e2faacad2ff4ce26a
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 17, 2026.

Transparency log

Security for polars-list-math 0.4.1

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