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

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.0
File Size Uploaded Provenance
polars_list_math-0.4.0.tar.gz 51.2 kB With provenance Details

Built distributions (wheels)

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

Download URL polars_list_math-0.4.0.tar.gz
Size 51.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c43c4f8d988f1a8d23a807f86c0c373ee8f2b6ff0c97ac108ced4715089a5e69
BLAKE2b-256 checksum
How to use checksums
096e64a5b00a9fba8f35168cf8aa522b63fe5511d85cd9063e1f81b98eb21285
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 16, 2026.

Transparency log

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

Download URL polars_list_math-0.4.0-cp313-cp313-win_amd64.whl
Size 4.9 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
222bcc42e2697f5536fd27c5d7f1409b2da7e7505fe85515f578cba5e613210c
BLAKE2b-256 checksum
How to use checksums
d8ef9181ff6b8eb235d381678ed8862796204eaf6539bc256838804fc734625e
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 16, 2026.

Transparency log

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

Download URL polars_list_math-0.4.0-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
630861c3fc1c4826b1918d0e7295a60553aab186b8640e8a978bb41fdf5608c4
BLAKE2b-256 checksum
How to use checksums
4b03918db4c087f7d311bafc9d0de8d1970f0da7d43befbddd6e5c430fee7624
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 16, 2026.

Transparency log

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

Download URL polars_list_math-0.4.0-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
3c71d8e95ee26c98ff5670e3222d201eabf2f7b67aa2c9f5d76c3502b550f902
BLAKE2b-256 checksum
How to use checksums
388cd851f2788c5fc0a0e891cb1ddbd95231b992dec646d8b1aabd283b538edf
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 16, 2026.

Transparency log

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

Download URL polars_list_math-0.4.0-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
12977fc34afc64dab2eec9ecb94a37902da849dea081e4ddc04f0bf570de86f1
BLAKE2b-256 checksum
How to use checksums
bda25ac43b7475ed3a5cbb83f18db79af15568afa5b3f1f376e39256b2319f43
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 16, 2026.

Transparency log

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

Download URL polars_list_math-0.4.0-cp312-cp312-win_amd64.whl
Size 4.9 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
d8dbc5c52838fa3d4a0639f4d64cc7440aabe8cb585d2fc260dc283bcf4eff6f
BLAKE2b-256 checksum
How to use checksums
0a2d6c34edda06f018c29551e2f7835a7d691fcd0df80023b85a3ab3ecfae609
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 16, 2026.

Transparency log

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

Download URL polars_list_math-0.4.0-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
11408497ed19ed0807340fab22eea6f85fc5dc00ee6511af5c8570cc55986b31
BLAKE2b-256 checksum
How to use checksums
389d153035023493fe2fdf368a7198e34bbfc67b74e7bbb12110838f04d61067
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 16, 2026.

Transparency log

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

Download URL polars_list_math-0.4.0-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
392d638833a9bc1b96f913d7a5be4a11455b026c324c9ef9468df67be752a796
BLAKE2b-256 checksum
How to use checksums
03ee59806b5b18c5414559e41f1e3c5f8c3a039e4cc80630075cbf89d434f925
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 16, 2026.

Transparency log

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

Download URL polars_list_math-0.4.0-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
ca23348a7da0a6e14f745baa1bca4331b3dc5f90e476dd7ab3bfc8609644a5dc
BLAKE2b-256 checksum
How to use checksums
c8cfd0d867a59a3683ef197beed57cc5680dbe1860872435adcfe2f1171cba81
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 16, 2026.

Transparency log

Security for polars-list-math 0.4.0

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.0.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 16, 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