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 boolean, 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.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| skewsplit-0.3.0.tar.gz | 53.3 kB | With provenance | Details for skewsplit-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| skewsplit-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for skewsplit-0.3.0-py3-none-any.whl |
Total release size: 122.5 kB
Release files / skewsplit-0.3.0.tar.gz
| Download URL | skewsplit-0.3.0.tar.gz |
|---|---|
| Size | 53.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7033f7571333cad89ce83cfc72fcbd72210670c886192bcf6260e7fbc0fe7368
|
|
BLAKE2b-256 checksum How to use checksums |
3f677d00cda8e3af6106a85a8c66db18f7cd28233c75cb403db6430a45086450
|
| 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 30, 2026.
Transparency logRelease files / skewsplit-0.3.0-py3-none-any.whl
| Download URL | skewsplit-0.3.0-py3-none-any.whl |
|---|---|
| Size | 69.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5cb9757e39742d8d1bd86c5057bf9eff5086baf03c9929c2ad94683d019584e2
|
|
BLAKE2b-256 checksum How to use checksums |
12b83698a0738d73c74d64482727c7dbff7fb357b86eb8f5527c80a62523541c
|
| 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 30, 2026.
Transparency logSecurity for skewsplit 0.3.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.
Attestation for skewsplit-0.3.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 30, 2026.
Transparency logA 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.