SCD Type 2 tables with DuckDB. Track historical changes to slowly-changing data.
Project description
scduck
Store time series of snapshots in a SCD Type 2 table.
13 days of data: 65 MB CSV -> 6.3 MB DuckDB (~10x compression)
How it works
Records are stored with valid_from / valid_to date ranges. When data doesn't change, no new rows are written. Only changes generate new records.
id | name | price | valid_from | valid_to
P001 | Widget| 9.99 | 2025-01-01 | 2025-03-15 # original price
P001 | Widget| 12.99 | 2025-03-15 | NULL # price changed
P002 | Gadget| 4.99 | 2025-01-01 | NULL # unchanged
valid_from: inclusive (>=)valid_to: exclusive (<), NULL = current
Usage
from scduck import SCDTable
# Define your schema
with SCDTable(
"products.duckdb",
table="products",
keys=["product_id"],
values=["name", "price", "category"]
) as db:
# Sync daily snapshots (pandas, polars, or pyarrow)
result = db.sync("2025-01-01", df_jan1) # returns SyncResult
db.sync("2025-01-02", df_jan2)
# Reconstruct any historical snapshot
snapshot = db.get_data("2025-01-01") # returns pyarrow Table
# Check synced dates
db.get_synced_dates() # ['2025-01-01', '2025-01-02']
Out-of-order sync
Dates can be synced in any order:
db.sync("2025-01-15", df) # sync Jan 15 first
db.sync("2025-01-01", df) # backfill Jan 1
db.get_data("2025-01-01") # returns correct snapshot
Example: SecurityMaster
import pandas as pd
from scduck import SCDTable
with SCDTable(
"security_master.duckdb",
table="securities",
keys=["security_id"],
values=["ticker", "mic", "isin", "description",
"sub_industry", "country", "currency", "country_risk"]
) as db:
df = pd.read_csv("SecurityMaster_20251201.csv")
db.sync("2025-12-01", df)
Installation
pip install scduck
# With pandas/polars support
pip install scduck[all]
Sync Logic
See SYNC_LOGIC.md for detailed operation cases.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scduck-0.1.1.tar.gz.
File metadata
- Download URL: scduck-0.1.1.tar.gz
- Upload date:
- Size: 48.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
025b5b2c291cf92bd29ac7984c03198070e9f673a910253d782e5cc8c1666030
|
|
| MD5 |
cb6478d7e45c7db3a863e0c42bd808e9
|
|
| BLAKE2b-256 |
370d28a011cd3da89372c5b76656b68d31671cf52a2b7a995786b5e6b538dc5a
|
Provenance
The following attestation bundles were made for scduck-0.1.1.tar.gz:
Publisher:
publish.yml on papasaidfine/scduck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scduck-0.1.1.tar.gz -
Subject digest:
025b5b2c291cf92bd29ac7984c03198070e9f673a910253d782e5cc8c1666030 - Sigstore transparency entry: 965019691
- Sigstore integration time:
-
Permalink:
papasaidfine/scduck@2c7fcee707dbc7efe8c37453996c71df1120f2ee -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/papasaidfine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2c7fcee707dbc7efe8c37453996c71df1120f2ee -
Trigger Event:
push
-
Statement type:
File details
Details for the file scduck-0.1.1-py3-none-any.whl.
File metadata
- Download URL: scduck-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55e35682a6c07a5201b3429758969e03c3d9f0099ae918e525f47d95976ea592
|
|
| MD5 |
e298b77fd37b3b8f5252f3751c0ed6c9
|
|
| BLAKE2b-256 |
53011ed4b5962a5153fdf1572d77578982bd044f468891c996cc7f01370c817b
|
Provenance
The following attestation bundles were made for scduck-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on papasaidfine/scduck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scduck-0.1.1-py3-none-any.whl -
Subject digest:
55e35682a6c07a5201b3429758969e03c3d9f0099ae918e525f47d95976ea592 - Sigstore transparency entry: 965019749
- Sigstore integration time:
-
Permalink:
papasaidfine/scduck@2c7fcee707dbc7efe8c37453996c71df1120f2ee -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/papasaidfine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2c7fcee707dbc7efe8c37453996c71df1120f2ee -
Trigger Event:
push
-
Statement type: