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.12.tar.gz (8.3 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.12-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dataclass-persistence-0.0.12.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

File hashes

Hashes for dataclass-persistence-0.0.12.tar.gz
Algorithm Hash digest
SHA256 35f697284cd7529449ec167e0db568ad493274689544594ab5e62d5e7cc34a98
MD5 d1a010e17d9d07e760f2a92dea08abeb
BLAKE2b-256 f726a8cf2d5749e3ce6757115628e5ba643046fb79cc4ed180b3496632ef5d6a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dataclass_persistence-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

File hashes

Hashes for dataclass_persistence-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 36a3ed1fd7ea247cea683c551bd267d9c688fb506116e04ccab4eaa5a31dfab7
MD5 fd705279ee9b407b8ebb3606c88e55a6
BLAKE2b-256 af31072d9984ede06b953431071fcafa61e6a82b0673cd7a322ae61c53e53554

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