Skip to main content

s3parq

Parquet file management in S3 for hive-style partitioned data

What is this?

In many ways, parquet standards are still the wild west of data. Depending on your partitioning style, metadata store strategy etc. you can tackle the big data beast in a multitude of different ways. This is an AWS-specific solution intended to serve as an interface between python programs and any of the multitude of tools used to access this data. s3parq is an end-to-end solution for:

  1. writing data from pandas dataframes to s3 as partitioned parquet.
  2. reading data from s3 partitioned parquet that was created by s3parq to pandas dataframes.

NOTE: s3parq writes (and reads) metadata into the s3 objects that is used to filter records before any file i/o; this makes selecting datasets faster, but also means you need to have written data with s3parq to read it with s3parq.

TLDR - to read with s3parq, you need to have written with s3parq

Basic Usage

we get data by dataset name.

import s3parq

bucket = 'mybucket'
key = 'path-in-bucket/to/my/dataset'
dataframe = pd.DataFrame(['some_big_data'])

## writing to s3
parq.publish(  bucket=bucket,
                key=key,
                dataframe=dataframe, 
                partitions= ['column1',
                            'column2'])

## reading from s3, getting only records with an id >= 150
pandas_dataframe = parq.fetch(  bucket=bucket,
                                key=key,
                                dataframe=dataframe, 
                                filter= {"partition":"id,
                                "values":150, 
                                "comparison":'>='})

Getting Existing Partition Values

a lot of pre-filtering involves trimming down your dataset based on the values already in another data set. To make that easier, s3parq provides a few super helpful helper functions:

partition = 'order_id'

## max value for order_id column, correctly typed
max_val = parq.get_max_partition_value(bucket,
                             key,
                             partition)

## partition values not in a list of order_ids. 
## if partition values are 1-6 would return [5,6] correctly typed.
list_of_vals = [0,1,2,3,4]
new_vals = parq.get_diff_partition_values(  bucket,
                                            key,
                                            partition,
                                            list_of_vals)

## list values not in partition value list
## if partition values are 3-8 would return [1,2] correctly typed.
list_of_vals = [1,2,3,4]
missing_vals = parq.get_diff_partition_values(  bucket,
                                                key,
                                                partition,
                                                list_of_vals,
                                                True)

## df of values in one dataset's partition and not another's
## this works by input -> where extra values would be, and comparison -> where they might not be
## similar to the get_diff_partition_values but handles it at the dataset level
missing_data = parq.fetch_diff( input_bucket, 
                                input_key, 
                                comparison_bucket, 
                                comparison_key, 
                                partition)

## all values for a partition
all_vals = parq.get_all_partition_values(   bucket,
                                            key,
                                            partition)

Gotchas

  • filters can only be applied to partitions; this is because we do not actually pull down any of the data until after the filtering has happened. This aligns with data best practices; the things you filter on regularly are the things you should partition on!

  • when using get_diff_partition_values remembering which set you want can be confusing. You can refer to this diagram: venn diagram of reverse value

Contribution

We welcome pull requests! Some basic guidelines:

  • test yo' code. code coverage is important!
  • be respectful. in pr comments, code comments etc;

Release files for s3parq 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for s3parq 1.0.2
File Size Uploaded
s3parq-1.0.2.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for s3parq 1.0.2
File Interpreter ABI Platform
s3parq-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.3 kB

Release files / s3parq-1.0.2.tar.gz

Download URL s3parq-1.0.2.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b0f6222e03d7e271e6fd4d173f0fae62270d1ce1bca6deb20fd554de35036e99
BLAKE2b-256 checksum
How to use checksums
d7992fe03d94bf08b21db43d0f9dc55406d1e0bf4455b6a1d0f6ca8bcc27d184
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.7.2

Release files / s3parq-1.0.2-py3-none-any.whl

Download URL s3parq-1.0.2-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b02ee43e62d63cd5f061dd20c6a3a7183d83d8191bd6c3ab7c98d0095a0b79c
BLAKE2b-256 checksum
How to use checksums
766960e71462d61d320f72417177539aafac9391b1e2a4bc43d7a9d654a44ff8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.7.2

Release history Release notifications | RSS feed

2.1.17

2 release files

2.1.16

2 release files

2.1.15

2 release files

2.1.14

2 release files

2.1.11

2 release files

2.1.9

2 release files

2.1.8

2 release files

2.1.7

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.0

2 release files

2.0.0

4 release files

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

1 release file

0.0.3

2 release files

0.0.2

3 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page