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.16.tar.gz (8.9 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.16-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dataclass-persistence-0.0.16.tar.gz
  • Upload date:
  • Size: 8.9 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.16.tar.gz
Algorithm Hash digest
SHA256 5779f392b832982e6277c5e33eb0ee6cc223268754a3c5f33400d4cf9d573c56
MD5 c2b4d213b2c82917417ea2d349acd915
BLAKE2b-256 aeb9b2626d78246428c84178a8f8e5219c8802c233144521402b245180ed97d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dataclass_persistence-0.0.16-py3-none-any.whl
  • Upload date:
  • Size: 7.8 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.16-py3-none-any.whl
Algorithm Hash digest
SHA256 08c737dd44e2baa6f3f2b200aa80e1ed3cdd150c7960c7571bd283c1c98ad0db
MD5 77af3473e9bb4f01a2e4df4c9702ea00
BLAKE2b-256 0d068a43bee3a2ae84a1f6a64409c01a26bbb98980ee080d7638c47bd379679f

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