Skip to main content

Persists information contained in dataclasses.

Project description

This program can be used to make dataclasses persistent by adding store and load functionality. The dataclass is stored in .json format which is by default compressed inside of a .zip file.

What makes dataclass-persistence special?
  • Support for numpy arrays

  • Support for nested dataclasses

  • Human readable storage format with small file size

Usage

Let your dataclass inherit from Persistent. Then the dataclass can be stored on disk using .store() and loaded from disk using .load().

In the example below, we create an instance of dataclass, which is stored to and loaded from disk.

from dataclass_persistence import Persistent
from dataclasses import dataclass
import numpy as np


@dataclass
class SomeData(Persistent):
    parameter_a: str
    array: np.ndarray


data = SomeData('my_string', np.array([0, 0]))
file = 'my_file'
data.store(file)
data_reconstructed = SomeData.load(file)

On disk the code above produces my_file.zip which contains my_file.json:

{
  "parameter_a": "my_string",
  "array": {"data": [0, 0], "dtype": "int32"}
}

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

dataclass-persistence-0.3.7.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

dataclass_persistence-0.3.7-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file dataclass-persistence-0.3.7.tar.gz.

File metadata

  • Download URL: dataclass-persistence-0.3.7.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for dataclass-persistence-0.3.7.tar.gz
Algorithm Hash digest
SHA256 d6eb543d439a332c1b1451e34fec3c9812b2e02f118eb5ec0d335dea2c296f92
MD5 e104992be532adf2e7569ea0778dd5c9
BLAKE2b-256 e745a8e7dc205c7e9c035ddb5a2ba68744a989e3fa27960654b945378d88656a

See more details on using hashes here.

File details

Details for the file dataclass_persistence-0.3.7-py3-none-any.whl.

File metadata

File hashes

Hashes for dataclass_persistence-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a2cdc6f5b3cc0099b9e3eea9fbd8fe70d974cb78d0871c9ff5ba0471e3b9c05f
MD5 ad7a409c6701c676b53a58bb5fb18214
BLAKE2b-256 53c6a56739b09bf6081c14c94527ba657d01f800c0613a7891121e7fce144dcc

See more details on using hashes here.

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