Skip to main content

Pure-python parquet parser, for education

Project description

Tests PyPI version

Por Qué: Pure-Python Parquet Parser

¿Por qué? ¿Por qué no?

Si, ¿pero por qué? ¡Porque, parquet, python!

[!WARNING] This is a project for education, it is NOT suitable for any production uses.

Overview

Por Qué is a pure-Python Apache Parquet parser built from scratch for educational purposes. It implements Parquet's binary format parsing without external dependencies, providing insights into how Parquet files work internally.

Features

  • Pure Python implementation - No native dependencies, built from scratch
  • Complete reader stack - Parse files, row groups, column chunks, and pages
  • Lazy data loading - Efficient memory usage with on-demand reading
  • Metadata inspection - Parse and display Parquet file metadata
  • Schema analysis - View detailed schema structure with logical types
  • Row group information - Inspect row group statistics and column metadata
  • Compression analysis - Calculate compression ratios and storage efficiency
  • HTTP support - Read Parquet files from URLs using range requests
  • CLI interface - Easy-to-use command-line tools for exploration

Installation

With pip:

pip install 'por-que[cli]'

Usage

Command Line Interface

The CLI uses a unified file/URL argument that auto-detects the source:

# Show help
porque --help

# View file summary (local file or URL)
porque metadata /path/to/file.parquet summary
porque metadata https://example.com/file.parquet summary

# View detailed schema
porque metadata file.parquet schema

# View file statistics and compression info
porque metadata file.parquet stats

# View row group information
porque metadata file.parquet rowgroups
porque metadata file.parquet rowgroups --group 0

# View column metadata
porque metadata file.parquet columns

# View key-value metadata
porque metadata file.parquet keyvalue
porque metadata file.parquet keyvalue "spark.version"

Python API

from por_que import ParquetFile
from por_que.util.http_file import HttpFile

# Read from local file
with open("data.parquet", "rb") as f:
    parquet_file = ParquetFile(f)
    print(f"Total rows: {parquet_file.num_rows()}")
    print(f"Columns: {parquet_file.columns()}")

    # Access metadata
    metadata = parquet_file.metadata
    print(f"Parquet version: {metadata.version}")
    print(f"Row groups: {len(metadata.row_groups)}")

# Read from URL
with HttpFile("https://example.com/data.parquet") as f:
    parquet_file = ParquetFile(f)

    # Lazy iteration over a column
    for value in parquet_file.column("user_id"):
        print(value)  # Values are yielded one at a time

    # Access specific row group
    row_group = parquet_file.row_group(0)
    column_reader = row_group.column("email")
    for page in column_reader.read():
        # Pages contain raw data (decoding not yet implemented)
        page_header, raw_data = page
        print(f"Page type: {page_header.type}")

What You'll Learn

By exploring this codebase, you can learn about:

  • Parquet file format - Binary structure, magic bytes, footer layout
  • Thrift protocol - Binary serialization format used by Parquet
  • Schema representation - How nested and complex data types are encoded
  • Compression techniques - Various compression algorithms and their efficiency
  • Column storage - Columnar storage benefits and trade-offs
  • Metadata organization - How Parquet organizes file and column statistics
  • Lazy loading patterns - Efficient data access without loading entire files
  • Binary parsing - Low-level byte manipulation and struct unpacking

Educational Focus

This implementation prioritizes readability and understanding over performance:

  • Explicit parsing logic instead of generated Thrift code
  • Comprehensive comments explaining binary format details
  • Step-by-step Thrift deserialization
  • Clear separation of concerns between parsing and data structures
  • Educational debug logging (enable with logging.basicConfig(level=logging.DEBUG))
  • Structured architecture mirroring Parquet's physical layout

Requirements

  • Python 3.13+
  • No runtime dependencies for core parsing
  • Click for CLI interface (optional)

Architecture

src/por_que/
├── cli/                     # Command-line interface
│   ├── _cli.py             # Click CLI definitions
│   ├── formatters.py       # Output formatting functions
│   └── exceptions.py       # CLI-specific exceptions
├── parsers/                 # Low-level binary parsers
│   ├── parquet/            # Parquet format parsers
│   │   ├── metadata.py     # Metadata parser
│   │   ├── page.py         # Page header parser
│   │   ├── schema.py       # Schema parser
│   │   └── ...             # Other format parsers
│   └── thrift/             # Thrift protocol implementation
│       ├── parser.py       # Core Thrift parser
│       └── enums.py        # Thrift type definitions
├── readers/                 # High-level reader classes
│   ├── row_group.py        # Row group reader
│   ├── column_chunk.py     # Column chunk reader
│   └── page.py             # Page reader
├── util/                    # Utilities
│   └── http_file.py        # HTTP range request support
├── parquet_file.py         # Main entry point
├── protocols.py            # Type protocols
├── types.py                # Data structures and types
├── enums.py                # Parquet format enums
├── stats.py                # Statistics calculation
└── exceptions.py           # Core exceptions

Current Capabilities

Implemented Features

  • Complete metadata parsing - All Parquet metadata structures
  • Schema parsing - Full schema tree with logical types
  • Page header parsing - All page types (DATA_PAGE, DATA_PAGE_V2, DICTIONARY_PAGE)
  • Row group access - Lazy readers for row groups and columns
  • Statistics parsing - Min/max values and null counts
  • HTTP support - Range requests for remote file reading
  • Memory efficiency - Lazy loading throughout the stack

Work in Progress

  • Data decoding - Converting raw page data to Python values
  • Compression support - Snappy, GZIP, LZ4, Zstd decompression
  • Encoding support - PLAIN, DICTIONARY, RLE, BIT_PACKED decoding
  • Nested data - Handling definition and repetition levels

Future Development

  • Complete value extraction with all encodings
  • Schema inference and validation
  • Performance optimizations

Not Planned

  • Write support (creating Parquet files)

Contributing

This is primarily an educational project. Feel free to:

  • Report bugs or parsing issues
  • Suggest improvements for educational value
  • Add more comprehensive test cases
  • Improve documentation and comments

License

Apache License 2.0

Why "Por Qué"?

Because asking "why" leads to understanding! This project exists to answer "why does Parquet work the way it does?" by implementing it from first principles.

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

por_que-0.0.4.tar.gz (106.6 kB view details)

Uploaded Source

Built Distribution

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

por_que-0.0.4-py3-none-any.whl (56.9 kB view details)

Uploaded Python 3

File details

Details for the file por_que-0.0.4.tar.gz.

File metadata

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

File hashes

Hashes for por_que-0.0.4.tar.gz
Algorithm Hash digest
SHA256 20f337eb680777d5508206ca165beb3b19703c75a3ec69ceea6d341588fc73cb
MD5 6c2802787d81e43b9e7c91d797fa6bfb
BLAKE2b-256 5b15f6ccf5ef7873f71c07257463a79ea82735678d805e71b5211530d58a9f1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for por_que-0.0.4.tar.gz:

Publisher: release.yml on jkeifer/por-que

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

File details

Details for the file por_que-0.0.4-py3-none-any.whl.

File metadata

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

File hashes

Hashes for por_que-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7e715b1a8fb0210b33f08118b815b01ef618bbfb87cb61f8dd550a7f29dd3f22
MD5 5238c8d3d4245ddbf7c09c57a8cde831
BLAKE2b-256 88b426160b5b92a20ebcb9c96edaef3a440f35f9bb561f15e7612512c89e1118

See more details on using hashes here.

Provenance

The following attestation bundles were made for por_que-0.0.4-py3-none-any.whl:

Publisher: release.yml on jkeifer/por-que

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