SSB Parquedit
Project description
SSB Parquedit
A Python package for manually editing tabular data stored as Parquet files on DaplaLab — Statistics Norway's cloud data platform. Built on top of DuckDB and the DuckLake catalog, it provides a clean, SQL-injection-safe Python interface for creating tables, inserting data, and querying results directly from Google Cloud Storage (GCS).
Features
- Create tables from a pandas DataFrame, a JSON Schema dict, or an existing GCS Parquet file
- Insert data from a pandas DataFrame or a
gs://Parquet path — rows are automatically assigned a unique_id(UUID) - Query tables with structured filters, column selection, sorting, pagination, and multiple output formats (
pandas,polars,pyarrow) - Count rows with optional structured filter conditions
- Check table existence safely
- Partition tables by one or more columns
- DuckLake catalog integration — metadata stored in PostgreSQL, data stored in GCS
- SQL injection prevention — all user-supplied filter values are parameterized; column names, table names, and
ORDER BYclauses are validated against strict allowlists - Auto-configuration — reads Dapla environment variables to build connection config automatically
Requirements
- Python
>=3.11, <4.0 - Access to a DaplaLab environment with the following environment variables set:
DAPLA_GROUP_CONTEXT— e.g.dapla-ffunk-developersDAPLA_ENVIRONMENT— e.g.testorprod
- A PostgreSQL instance reachable at
localhostfor DuckLake metadata storage - A GCS bucket following the naming convention
ssb-{team-name}-data-produkt-{environment}
Python dependencies
| Package | Version |
|---|---|
duckdb |
==1.4.1 |
pandas |
>=3.0.0, <4.0.0 |
polars |
>=1.38.1, <2.0.0 |
pyarrow |
>=23.0.1, <24.0.0 |
gcsfs |
>=2026.1.0, <2027.0.0 |
click |
>=8.0.1 |
Installation
poetry add ssb-parquedit
Usage
Basic setup
ParquEdit reads its connection configuration automatically from Dapla environment variables. You can also pass a custom config dict.
from ssb_parquedit import ParquEdit
# Auto-configure from environment
con = ParquEdit()
# Or pass a custom config
con = ParquEdit(config={
"dbname": "my-database",
"dbuser": "my-group@dapla-group-sa-t-57.iam",
"data_path": "gs://my-bucket/.parquedit_data",
"catalog_name": "my_catalog",
"metadata_schema": "my_schema",
})
Creating a table
Tables can be created from a DataFrame schema, a JSON Schema dict, or an existing Parquet file.
import pandas as pd
df = pd.DataFrame({"name": ["Alice", "Bob"], "age": [30, 25]})
# Create table from DataFrame (empty — schema only)
con.create_table("my_table", source=df, product_name="my-product")
# Create and immediately populate with data
con.create_table("my_table", source=df, product_name="my-product", fill=True)
# Create from a JSON Schema
schema = {
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
}
}
con.create_table("my_table", source=schema, product_name="my-product")
# Create from an existing GCS Parquet file (schema inferred from file)
con.create_table("my_table", source="gs://my-bucket/path/to/file.parquet", product_name="my-product")
# Create with partitioning
con.create_table("my_table", source=df, product_name="my-product", part_columns=["age"])
Note:
product_nameis required and is stored as a comment on the table. Table names must be lowercase, start with a letter or underscore, and contain only lowercase letters, numbers, and underscores (max 20 characters).
Inserting data
# Insert from a DataFrame
con.insert_data("my_table", source=df)
# Insert from a GCS Parquet file
con.insert_data("my_table", source="gs://my-bucket/path/to/file.parquet")
Each inserted row is automatically assigned a unique _id (UUID string).
Querying data
# View all rows (returns pandas DataFrame by default)
result = con.view("my_table")
# Limit and offset (pagination)
result = con.view("my_table", limit=10, offset=20)
# Select specific columns
result = con.view("my_table", columns=["name", "age"])
# Sort results
result = con.view("my_table", order_by="age DESC")
# Return as polars or pyarrow
result = con.view("my_table", output_format="polars")
result = con.view("my_table", output_format="pyarrow")
Filtering
Filters are structured dicts — never raw SQL strings — ensuring SQL injection safety.
# Single condition
con.view("my_table", filters={"column": "age", "operator": ">", "value": 25})
# Multiple conditions (implicit AND)
con.view("my_table", filters=[
{"column": "age", "operator": ">", "value": 25},
{"column": "name", "operator": "LIKE", "value": "A%"},
])
# Explicit AND / OR
con.view("my_table", filters={
"or": [
{"column": "name", "operator": "=", "value": "Alice"},
{"column": "name", "operator": "=", "value": "Bob"},
]
})
# IN operator
con.view("my_table", filters={"column": "age", "operator": "IN", "value": [25, 30, 35]})
# BETWEEN operator
con.view("my_table", filters={"column": "age", "operator": "BETWEEN", "value": [20, 40]})
# NULL checks
con.view("my_table", filters={"column": "name", "operator": "IS NOT NULL"})
Supported operators: =, !=, <>, <, >, <=, >=, LIKE, IN, NOT IN, BETWEEN, IS NULL, IS NOT NULL.
Counting rows
total = con.count("my_table")
active_adults = con.count("my_table", filters=[
{"column": "age", "operator": ">=", "value": 18},
])
Checking table existence
if con.exists("my_table"):
print("Table found")
Security
SSB Parquedit is designed with SQL injection prevention as a first-class concern. See SQL_INJECTION_PREVENTION.md and STRUCTURED_FILTERS.md for a detailed description of the sanitization strategy.
Key points:
- All filter values are passed as parameterized query parameters (never interpolated into SQL strings)
- Column names, table names, and ORDER BY clauses are validated against strict allowlists before being used in query construction
- Raw SQL string filters are not accepted
Project structure
src/ssb_parquedit/
├── parquedit.py # ParquEdit facade — main public API
├── connection.py # DuckDB + DuckLake catalog connection management
├── ddl.py # DDL operations (CREATE TABLE, partitioning)
├── dml.py # DML operations (INSERT)
├── query.py # Query operations (SELECT, COUNT, EXISTS)
├── functions.py # Environment helpers (Dapla config auto-detection)
└── utils.py # Schema utilities and SQL sanitization
Contributing
Contributions are very welcome. To learn more, see the Contributor Guide.
License
Distributed under the terms of the MIT license. SSB Parquedit is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Credits
This project was generated from Statistics Norway's SSB PyPI Template. Maintained by Team Fellesfunksjoner at Statistics Norway (Data Enablement Department 724).
Project details
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 ssb_parquedit-0.0.2.tar.gz.
File metadata
- Download URL: ssb_parquedit-0.0.2.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a241ca4f77646cbfff68855ef1075de9143250867f3a4b4cc4aff93041158ee5
|
|
| MD5 |
26b6b464db56d48d37ac56054f6c1a8f
|
|
| BLAKE2b-256 |
24bc438800cbdd897ef91532a814b6d220890e7d5035e3424a8fb46633cd162c
|
Provenance
The following attestation bundles were made for ssb_parquedit-0.0.2.tar.gz:
Publisher:
release.yml on statisticsnorway/ssb-parquedit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ssb_parquedit-0.0.2.tar.gz -
Subject digest:
a241ca4f77646cbfff68855ef1075de9143250867f3a4b4cc4aff93041158ee5 - Sigstore transparency entry: 1114791484
- Sigstore integration time:
-
Permalink:
statisticsnorway/ssb-parquedit@34cfca1d61db4614575446c47227367b82c6e42c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/statisticsnorway
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@34cfca1d61db4614575446c47227367b82c6e42c -
Trigger Event:
push
-
Statement type:
File details
Details for the file ssb_parquedit-0.0.2-py3-none-any.whl.
File metadata
- Download URL: ssb_parquedit-0.0.2-py3-none-any.whl
- Upload date:
- Size: 21.0 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 |
1e44d7711cbd28b28546f1cede6981163570fb45b36a69bad837635ea5fefd4b
|
|
| MD5 |
91d330e711459405ad77cdab6ec7252c
|
|
| BLAKE2b-256 |
5a78a113335f7fa29d5e87948373a7dda11a35ad73ecd39c07e278627cdaa257
|
Provenance
The following attestation bundles were made for ssb_parquedit-0.0.2-py3-none-any.whl:
Publisher:
release.yml on statisticsnorway/ssb-parquedit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ssb_parquedit-0.0.2-py3-none-any.whl -
Subject digest:
1e44d7711cbd28b28546f1cede6981163570fb45b36a69bad837635ea5fefd4b - Sigstore transparency entry: 1114791514
- Sigstore integration time:
-
Permalink:
statisticsnorway/ssb-parquedit@34cfca1d61db4614575446c47227367b82c6e42c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/statisticsnorway
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@34cfca1d61db4614575446c47227367b82c6e42c -
Trigger Event:
push
-
Statement type: