Skip to main content

Calculates the pickled size of an object

Project description

Sometimes it is handy to know how much space an object will need when it will be serialized with pickle without actually pickling it. Especially when the object is large, pickling can be slow and memory consuming.

This library can calculate the exact space requirement without actually pickling it. It still has to make a pass through the object tree, which takes time, especially with many small objects. The major advantage is that it won’t take significant memory.

picklesize has special support for numpy arrays to calculate the size without the array->`str`->`file` procedure of regular pickling that requires at least two copy operations.

Usage

The API is kept similar to the one of pickle:

import picklesize
nbytes = picklesize.picklesize(obj, protocol=pickle.HIGHEST_PROTOCOL)

Currently only protocol 2 (better known as pickle.HIGHEST_PROTOCOL ) is supported.

Bug Reports and other contributions

This project is hosted here picklesize github page.

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

picklesize-0.1.1.zip (9.5 kB view hashes)

Uploaded Source

Supported by

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