Skip to content

feat(storage): profile-based S3 auth and hive-partitioned datasets - #2

Merged
gmermoud merged 1 commit into
mainfrom
feat/s3-profiles-hive-datasets
Jul 22, 2026
Merged

feat(storage): profile-based S3 auth and hive-partitioned datasets#2
gmermoud merged 1 commit into
mainfrom
feat/s3-profiles-hive-datasets

Conversation

@gmermoud

Copy link
Copy Markdown
Contributor

What & why

Adds a small library to read/write data to Switch Cloud S3 using ~/.aws/credentials profiles, plus a scalable Hive-partitioned Parquet dataset layer (using polars).

Changes

  • storage/credentials.py (new, shared)resolve_s3_credentials(profile, key_id, key_secret)S3Credentials. Precedence: named profile from ~/.aws/credentials → explicit keys → S3_ACCESS_KEY_ID/S3_SECRET_ACCESS_KEY. Used by both the boto3 client and the PyArrow filesystem.
  • storage/dataset.py (new) — Hive-partitioned datasets:
    • get_s3_filesystem(endpoint_url, profile=...)pyarrow.fs.S3FileSystem bound to the Switch endpoint.
    • write_dataset(df, fs, bucket, path, partition_cols=[...]) — polars DataFrame/Arrow Tablecol=value/ partitioned Parquet.
    • read_dataset(fs, bucket, path, columns=..., filters=...) → polars DataFrame, with partition pruning via pyarrow.dataset.field(...).
  • storage/s3.pyget_s3_client gains a profile argument; credential logic delegated to the shared resolver.
  • storage/README.md (new) — usage guide incl. a local-CSV → partitioned-Parquet-on-S3 walkthrough. Top-level README.md updated.
  • pyproject.tomlstorage extra now includes polars>=1.0 and pyarrow>=15.0.
  • tests/test_dataset.py (new) — round-trips, partition pruning, column projection, credential resolution (incl. profile from a shared-credentials file).

Notes

  • ⚠️ Positional-arg change: profile is the first credential arg of get_s3_client, so get_s3_client(endpoint, key_id, key_secret) positionally now needs keywords. Happy to move profile last if preferred.
  • Fixed a bug caught in testing where an absolute local path had its leading / stripped (would silently write to the cwd).

Testing

70 tests pass; ruff check . clean.

Read/write data to S3-compatible storage (SwitchCloud) using
~/.aws/credentials profiles, plus a polars-based layer for
hive-partitioned Parquet datasets that scale to large tables.

- credentials.py: shared resolve_s3_credentials() used by both the
  boto3 client and the PyArrow filesystem. Precedence: named profile
  from ~/.aws/credentials, then explicit keys, then S3_* env vars.
- dataset.py: get_s3_filesystem(), write_dataset(), read_dataset() for
  hive-partitioned Parquet with polars; filters prune partitions.
- s3.py: get_s3_client() gains a `profile` argument.
- storage/README.md: usage guide incl. local-CSV -> partitioned Parquet.
- Add polars + pyarrow to the `storage` extra; tests for both.
@gmermoud
gmermoud force-pushed the feat/s3-profiles-hive-datasets branch from a943bcc to 23fc41a Compare July 22, 2026 08:54
@gmermoud
gmermoud merged commit e4f2381 into main Jul 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant