Skip to main content

A lightweight Python library for efficiently reading year-month-day partitioned Parquet datasets.

Project description

shardate

PyPI version Python versions License Build Status Coverage Code style: ruff

A lightweight Python library for efficiently reading year-month-day partitioned Parquet datasets with PySpark.

Installation

pip install shardate

Overview

shardate provides a clean, dataclass-based API for working with Parquet datasets that are partitioned in a year/month/day directory structure (e.g., y=2025/m=01/d=15/). It's built on PySpark and designed for efficient date-based filtering and data retrieval.

Features

  • Date-based reading: Read data for specific dates, date ranges, or collections of dates
  • End-of-month support: Dedicated functionality for reading end-of-month data
  • Flexible partitioning: Customizable partition format (defaults to y=%Y/m=%m/d=%d)
  • PySpark integration: Seamlessly works with existing PySpark workflows
  • Type hints: Full type annotation support for better development experience
  • Well-tested: Comprehensive test suite ensuring reliability

Quick Start

Basic Usage

from datetime import date
from shardate import Shardate

# Create a Shardate instance for your data path
reader = Shardate("/path/to/your/partitioned/data")

# Read data for a specific date
df = reader.read_by_date(date(2025, 1, 15))

# Read data between two dates (inclusive)
df = reader.read_between(date(2025, 1, 1), date(2025, 1, 31))

# Read data for specific dates
target_dates = [date(2025, 1, 1), date(2025, 1, 15), date(2025, 1, 31)]
df = reader.read_by_dates(target_dates)

# Read only end-of-month data within a date range
df = reader.read_eoms_between(date(2025, 1, 1), date(2025, 3, 31))

Custom Partition Format

# If your data uses a different partition format
reader = Shardate("/path/to/data", partition_format="year=%Y/month=%m/day=%d")
df = reader.read_by_date(date(2025, 1, 15))

Working with PySpark

from pyspark.sql import SparkSession
from shardate import Shardate

# Ensure you have an active SparkSession
spark = SparkSession.builder.appName("SharDate Example").getOrCreate()

# Use Shardate as normal
reader = Shardate("/path/to/data")
df = reader.read_by_date(date(2025, 1, 15))

# The returned DataFrame is a standard PySpark DataFrame
df.show()
df.filter(df.column_name == "some_value").count()

API Reference

Shardate Class

@dataclass
class Shardate:
    path: str
    partition_format: str = "y=%Y/m=%m/d=%d"

Methods

  • read_by_date(target_date: date) -> DataFrame: Read data for a specific date
  • read_between(start_date: date, end_date: date) -> DataFrame: Read data between two dates (inclusive)
  • read_by_dates(target_dates: Iterable[date]) -> DataFrame: Read data for specific dates
  • read_eoms_between(start_date: date, end_date: date) -> DataFrame: Read end-of-month data within a date range

Data Structure Requirements

Your Parquet data should be partitioned in directories following this structure:

data/
├── y=2025/
│   ├── m=01/
│   │   ├── d=01/
│   │   │   └── part-*.parquet
│   │   ├── d=02/
│   │   │   └── part-*.parquet
│   │   └── d=31/
│   │       └── part-*.parquet
│   └── m=02/
│       └── ...
└── y=2024/
    └── ...

Development

Setup

# Clone the repository
git clone https://github.com/yoichiojima-2/shardate.git
cd shardate

# Install development dependencies (using uv)
uv sync --dev

Testing

# Run all tests
make test

# Or use uv directly
uv run pytest -vvv

Code Quality

# Run linting and formatting
make lint

# Or use uv directly
uv run ruff check --fix .
uv run ruff format .

Building

# Build the package
make build

# Clean build artifacts
make clean

Requirements

  • Python: 3.12+
  • PySpark: 4.0+
  • python-dateutil: 2.9.0.post0+

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes and add tests
  4. Run the test suite (make test)
  5. Run code quality checks (make lint)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Links

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

shardate-2025.9.9.4.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shardate-2025.9.9.4-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file shardate-2025.9.9.4.tar.gz.

File metadata

  • Download URL: shardate-2025.9.9.4.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for shardate-2025.9.9.4.tar.gz
Algorithm Hash digest
SHA256 f22a2f948b36a58fd66ef4a60e77b587be823d98156b962035c8bd2cee1cdbc7
MD5 f0419861379627208b0b3a26d7328ff5
BLAKE2b-256 cf9754e1230f19a72b2a54382425b547cc836b1304b976cc70a8ea1dc9dbe513

See more details on using hashes here.

Provenance

The following attestation bundles were made for shardate-2025.9.9.4.tar.gz:

Publisher: release.yml on yoichiojima-2/shardate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shardate-2025.9.9.4-py3-none-any.whl.

File metadata

  • Download URL: shardate-2025.9.9.4-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for shardate-2025.9.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 19930afd2046ccf2501f293accf5961ab7ee5fc4887e0a03a0644740df27814f
MD5 19953acb47e9ac1ab2bad2c6b031bd17
BLAKE2b-256 4be39822004033a573ecf54f1255afa291ecfe1e394c28d36fe8116742f5fc10

See more details on using hashes here.

Provenance

The following attestation bundles were made for shardate-2025.9.9.4-py3-none-any.whl:

Publisher: release.yml on yoichiojima-2/shardate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page