Skip to main content

skewsplit

skewsplit reads a database column's distribution and returns balanced, index-friendly range predicates for the predicates argument of Spark's JDBC reader, together with a report of the remaining skew.

For PostgreSQL, it plans from the column's statistics in pg_stats, without scanning the table. NULL rows get their own predicate, a value too frequent to split gets its own col = value predicate, and the predicates match every row exactly once whatever the data.

Status: early development (pre-alpha). The API can change in any 0.x release.

Install

pip install "skewsplit[postgres]"

The postgres extra installs psycopg, which also needs libpq: add psycopg[binary] if your system has none.

Use

from skewsplit import postgres

plan = postgres.plan("host=db dbname=shop user=reader", "public.orders", "customer_id", 16)
print(plan.report)
df = spark.read.jdbc(url, "public.orders", predicates=plan.predicates, properties=properties)

That reads the column's statistics in pg_stats. When they are missing or out of date, plan from a sample of the table instead:

plan = postgres.plan(dsn, "public.orders", "customer_id", 16, strategy="sample", seed=7)

For a column of another type, such as text or uuid, method="hash" plans hash predicates; every partition then reads the whole table.

strategy="auto" chooses for you: the statistics when they are fresh, a sample when they are missing or out of date, and hash predicates for a column that ranges cannot split. plan.source["auto"] and the report say which and why.

To plan a filtered read, such as the last 90 days, pass the filter as where=, and apply the same filter in Spark's read. It is SQL that skewsplit runs as it is: pass only text you trust. The main README shows how.

When accuracy matters more than planning time, strategy="exact" reads every row. It scans the whole table three times and sorts the column, so set statement_timeout_ms on a large table.

The planner itself needs no database:

>>> import skewsplit
>>> plan = skewsplit.plan(
...     {
...         "column": "customer_id",
...         "type": "int4",
...         "null_rows": 100,
...         "mcv": [{"value": "7", "rows": 60}, {"value": "42", "rows": 500}],
...         "histogram": {"bounds": ["1", "250", "500", "750", "1000"], "rows": 400},
...     },
...     4,
... )
>>> for predicate in plan.predicates:
...     print(predicate)
"customer_id" IS NULL
"customer_id" < 42
"customer_id" = 42
"customer_id" > 42 AND "customer_id" < 520
"customer_id" >= 520

From the command line, skewsplit plan --table public.orders --column customer_id --partitions 16 prints the same report, --strategy sample plans from a sample, --strategy exact from every row, and --format pyspark prints the code that reads the table.

The output contains real values from the column: treat plans, reports and logs like the data they describe.

The repository has the full documentation: the command line, when to use hash-mod instead, limitations and supported versions.

Metadata

Release files for skewsplit 0.2.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 skewsplit 0.2.0
File Size Uploaded Provenance Actions
skewsplit-0.2.0.tar.gz 52.7 kB With provenance Details for skewsplit-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 121.3 kB

Release files / skewsplit-0.2.0.tar.gz

Download URL skewsplit-0.2.0.tar.gz
Size 52.7 kB
Tags Source
SHA-256 checksum
How to use checksums
32bbb82644e65c6ef91c6f4bd0a9440e14cbcb4a8710801bc1009ab067544c6a
BLAKE2b-256 checksum
How to use checksums
2450cc2decb2bbddb3ee5d4ddd3a6e3ad22b15fbbc5f37a6daf18a19350096f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Release files / skewsplit-0.2.0-py3-none-any.whl

Download URL skewsplit-0.2.0-py3-none-any.whl
Size 68.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6302d7f5b3a08dd03c50a18f10f573dd4bcceb39f915a8776807cc1b651cd995
BLAKE2b-256 checksum
How to use checksums
c51710f1b960f9c6679dc419059c2a9dbd1fc71935dc118a3edb82b52b8a8ba7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Security for skewsplit 0.2.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for skewsplit-0.2.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 Nov 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