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.14.tar.gz (8.7 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.14-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dataclass-persistence-0.0.14.tar.gz
  • Upload date:
  • Size: 8.7 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.14.tar.gz
Algorithm Hash digest
SHA256 938ebd6a3ecb34d4bb493acfae5f64bbbb1ba017db4989b24931fe2e0f33583f
MD5 9390571b6fdd055e889251d8c293c67e
BLAKE2b-256 3a124c59b735e15acabfe117f76d024c33d24fcfc0840d4c3af71417fb2534c6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dataclass_persistence-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 7.6 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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 67a7e5496b1d8af9716f7d7c20128cb57e131fe55a6ce28e3347fba3dca2dbf4
MD5 21d4c33e7ef3b346185808dcba1c0f74
BLAKE2b-256 fd3cfde9d352a2fd9112b252981cbc65e02cd2bfe12f8f5a3e27b5198d413d08

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