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.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 skewsplit 0.2.1
File Size Uploaded Provenance Actions
skewsplit-0.2.1.tar.gz 52.8 kB With provenance Details for skewsplit-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 121.6 kB

Release files / skewsplit-0.2.1.tar.gz

Download URL skewsplit-0.2.1.tar.gz
Size 52.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7b285b0fdf3d2254098ff9605ccec222c4ecee67af3fd770eb90b9b2e8bb734e
BLAKE2b-256 checksum
How to use checksums
a5a41869fab43f872c764836d63609e2e7bb9d308f71456fea1abf54b2d6b7a7
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 26, 2026.

Transparency log

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

Download URL skewsplit-0.2.1-py3-none-any.whl
Size 68.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e9d2c76b7244ccbf3697feb0475e5facdfc1c4571f5e709a3e0c15cc2f6794b
BLAKE2b-256 checksum
How to use checksums
3ae32b4f3d8ee0ecb79621132aaa2c740c4a3bcf002e47c145ff15be68e95fab
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 26, 2026.

Transparency log

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

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

Select from 2 files

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