Skip to main content

This package enables to persist information stored 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 PersistentDataclass. Then the dataclass can be stored on disk using .store_to_disk() and loaded from disk using .load_from_disk().

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

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


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


data = SomeData('my_string', np.array([0, 0]))
file = 'my_file'
data.store_to_disk(file)
data_reconstructed = SomeData.load_from_disk(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.0.8.tar.gz (8.2 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.0.8-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dataclass-persistence-0.0.8.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.3

File hashes

Hashes for dataclass-persistence-0.0.8.tar.gz
Algorithm Hash digest
SHA256 5fb0df00831cb4043704604d5ef90535a7f1dd5b77103ae4ec772b09fb6a5669
MD5 7f470f0d4a9c6de9c34336dd44261191
BLAKE2b-256 9f456523ec5d1d9f7bd137b836969f5b82d7eead559f6974cafe85026e69a64d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dataclass_persistence-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.3

File hashes

Hashes for dataclass_persistence-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c9cefca3fc477a0b6d8c9d832b5043a3efbc38656eea3a85feed57d486982444
MD5 e9e5088d360ce517a05cc44a08c57894
BLAKE2b-256 00c1e0c6856cea19e667949387d7f18ce4a44e792e7e1dc0301bad396ba0d762

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