Skip to main content

superleaf

Readable, composable filters for pandas and plain Python data.

pip install superleaf           # numpy + pandas only
pip install "superleaf[fuzzy]"  # adds F.fuzzy_match (rapidfuzz)

Filters as data

A filter is a dict mapping columns to conditions. It can be built in one place, stored, combined and passed to dfilter:

import pandas as pd
from superleaf import F, dfilter, partition

df = pd.DataFrame({
    "type": ["T4a", "T4b", "Mi1", None, "Tm3"],
    "side": ["L", "R", "L", "R", "L"],
    "size": [10.0, None, 3.5, 7.0, -1.0],
})

left_t4 = {"type": F.startswith("T4"), "side": "L"}
dfilter(df, **left_t4)

dfilter(df, size=F.isna | F.lt(0))
dfilter(df, type=F.isin(["Mi1", "Tm3"]), columns=["type", "size"])
kept, dropped = partition(df, type=F.notna)

Keyword values are matched by equality, F.* predicates and other callables are applied to each value, and columns= selects columns by name or predicate. Use where for conditions across columns:

from superleaf import where

dfilter(df, where(lambda d: d["size"] > d["size"].median()))

Predicates work on values and columns

F predicates combine with |, & and ~, and evaluate either a single value or a whole Series with the same result:

is_valid = F.gt(0) | F.eq("n/a")
is_valid(5)                        # True
is_valid(None)                     # False: missing values only satisfy ne
is_valid.on_series(df["size"])     # boolean Series; vectorized where possible

& and | short-circuit like and and or, so a type check on the left guards the right.

The same predicate filters lists:

from superleaf.sequences import filtered, partitioned

filtered(F.startswith("T4"), ["T4a", "Mi1", "T4b"])   # ["T4a", "T4b"]

Available predicates: eq, ne, lt, le, gt, ge, isin, contains, contains_all, contains_any, startswith, endswith, startswith_one_of, endswith_one_of, matches_regex, fuzzy_match, isna, notna, isinf, notinf. Pass fallback= (and optionally exceptions=) to return a value instead of raising, e.g. F.lt(0, fallback=False)("a") is False.

Custom predicates and pipelines:

from superleaf.operators import attr_getter, bool_operator, str_op

is_even = bool_operator(lambda x: x % 2 == 0)
lower_starts_e = str_op("lower") >> F.startswith("e")   # pipe with >>
get_score = attr_getter("score") >> F.ge(0.5)

Compared with alternatives

Reusable as data Works on scalars and lists Missing values / mixed types
df.query("a > 0 and b == 'x'") as strings no follows pandas
df.loc[lambda d: (d.a > 0) & (d.b == "x")] as functions no follows pandas
polars expressions yes no (polars frames only) follows polars
dfilter(df, a=F.gt(0), b="x") yes yes same result per value as plain Python, with fallback=

Other utilities

  • superleaf.sequences: mapped, filtered, flatten, flatmap, groupby, partitioned
  • superleaf.dataframe: reorder_columns, expand_dict_to_cols
  • superleaf.collections: OrderedSet, SummableDict

See the API reference and CHANGELOG.

Metadata

Release files for superleaf 0.9.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 superleaf 0.9.0
File Size Uploaded
superleaf-0.9.0.tar.gz 20.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for superleaf 0.9.0
File Interpreter ABI Platform
superleaf-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 44.8 kB

Release files / superleaf-0.9.0.tar.gz

Download URL superleaf-0.9.0.tar.gz
Size 20.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ef43ce9191db10fd4dda58b6477ab47a5659f6e68f5fcf0d431c4c445d2d68c4
BLAKE2b-256 checksum
How to use checksums
c6ed3b5a874064216d7b3f99e25aeb448635e01c77491a58dc4eb63494f1d43f
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 Oct 17, 2026.

Transparency log

Release files / superleaf-0.9.0-py3-none-any.whl

Download URL superleaf-0.9.0-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2739ff74e503871507a4575379ac00638eb0c1eb121c3cee533da9a683093a55
BLAKE2b-256 checksum
How to use checksums
6e93a16b88103a2bb1f458e2b40d7560ec91950236755162c5fb3b94289870e8
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 Oct 17, 2026.

Transparency log

Release history Release notifications | RSS feed

1.0.0

2 release files

This release

0.9.0 This release

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.4

2 release files

0.2.0

2 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