Registry / ai-ml / petastorm

petastorm

JSON →
library0.13.1pypypiunverified

Petastorm is a Python library that enables single-node or distributed training of machine learning models directly from datasets stored in Parquet format. It provides data access for popular frameworks like TensorFlow, PyTorch, and Apache Spark. The current stable version is 0.13.1, with releases typically following a feature-driven cadence, often including release candidates before stable versions.

pip install petastorm
INSTALL
IMPORT
SIG · PETASTORM
P
petastorm
ai-mlpythonv0.13.1
Install
21.0s avg
Import
Disk
830MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.13.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.980 runs
installs and imports cleanly · install 0.1s · import 0.000s · 845.2MB
glibc
py 3.103.980 runs
installs and imports cleanly · install 42.0s · import 0.000s · 810MB
830MB installed
● package 830MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

make_reader
from petastorm import make_reader
from petastorm import make_reader

This quickstart demonstrates how to define a data schema, write sample data to a Parquet dataset using `make_writer`, and then read it back using `make_reader`. The example cleans up the temporary directory after execution. For real-world usage, consider configuring `reader_pool_type` and `num_epochs` based on your training requirements.

import os import shutil import numpy as np from petastorm import make_reader, make_writer from petastorm.unischema import Unischema, UnischemaField, ScalarCodec from petastorm.codecs import CompressedNdarrayCodec # 1. Define a schema for your data MySchema = Unischema( 'MySchema', [ UnischemaField('id', np.int32, (), ScalarCodec(np.int32), False), UnischemaField('value', np.float64, (), ScalarCodec(np.float64), False), UnischemaField('image', np.uint8, (10, 10, 3), CompressedNdarrayCodec(), False), ] ) # 2. Define a dataset path (using a temporary local directory for example) dataset_url = 'file:///tmp/petastorm_example_data' # Clean up previous data if it exists if os.path.exists('/tmp/petastorm_example_data'): shutil.rmtree('/tmp/petastorm_example_data') # 3. Write some dummy data to the Parquet dataset print(f"Writing dummy data to {dataset_url}...") with make_writer(dataset_url, MySchema, row_group_size_bytes=2 * 1024 * 1024) as writer: for i in range(10): writer.write( MySchema.make_row( id=i, value=float(i * 10), image=np.random.randint(0, 256, size=(10, 10, 3), dtype=np.uint8) ) ) print(f"Successfully wrote 10 rows.") # 4. Read data using make_reader # reader_pool_type='thread' is often suitable for local development. # For production, 'process' might be preferred depending on data access patterns. print("\nReading data from the dataset:") with make_reader(dataset_url, reader_pool_type='thread', num_epochs=1) as reader: for i, row in enumerate(reader): print(f"Row {i}: id={row.id}, value={row.value}, image_shape={row.image.shape}") if i >= 2: # Print only a few rows for brevity break print("Finished reading example data.") # Clean up the temporary dataset shutil.rmtree('/tmp/petastorm_example_data')
Debug
Known issues
breakingThe default `reader_pool_type` for `make_reader` changed from 'thread' to 'process' in Petastorm v0.13.0. This can cause issues if your data contains objects that are not picklable, or if you expect thread-based concurrency.
fix
If you encounter `TypeError: cannot pickle ...` or unexpected performance, explicitly set `reader_pool_type='thread'` in your `make_reader` call: `make_reader(..., reader_pool_type='thread', ...)`.
affects: >=0.13.0
deprecatedThe `PetastormDataset` class (e.g., from `petastorm.reader`) and direct instantiation of `Reader` were deprecated in favor of the `make_reader` factory function.
fix
Always use `from petastorm import make_reader` and instantiate readers via `make_reader(...)` for future compatibility and resource management.
affects: >=0.13.0
gotchaUsing Petastorm with TensorFlow or PyTorch requires installing the corresponding 'extras' (e.g., `pip install petastorm[tensorflow]`). Without these, you might miss framework-specific utilities or experience integration issues.
fix
Ensure you install Petastorm with the relevant extras for your ML framework: `pip install petastorm[tensorflow]` or `pip install petastorm[pytorch]`.
affects: All
gotchaWhen using `make_reader` with Spark, ensure `pyspark` is installed and the `spark` extra is included during Petastorm installation. Otherwise, Spark-specific modules will be missing.
fix
Install `pyspark` and Petastorm with the Spark extra: `pip install pyspark petastorm[spark]`.
affects: All
Upgrade
Version history
0.13.1latest on PyPI · released Jan 2, 2026
Audit
Dependencies
numpyrequiredCore dependency for array handling.
pyarrowrequiredRequired for Parquet file I/O operations.
pandasoptionalOften used for data manipulation before writing to Parquet or after reading.
pysparkoptionalRequired for petastorm.spark module when integrating with Apache Spark.
Agent activity
25 hits · last 30 days
node
20
Resources
petastorm — pip install petastorm · libregistry