Skip to main content

A python library for serializing dataclasses to bytes and back.

Project description

Databrief

databrief is a Python library for serializing dataclasses to bytes and deserializing bytes back to dataclasses.

Features

  • Compact serialization
  • Supports int, float, and bool field types

Installation

pip install databrief

Usage

Dumping a Dataclass to Bytes

To serialize a dataclass instance to bytes, use the dump function:

from databrief.databrief import dump
from dataclasses import dataclass

@dataclass
class TestData:
    a: int
    b: float
    c: bool

data = TestData(a=42, b=3.14, c=True)
serialized = dump(data)
print(serialized)

Loading Bytes to a Dataclass

To deserialize bytes back to a dataclass instance, use the load function:

from databrief.databrief import load

deserialized = load(serialized, TestData)
print(deserialized)

Example

Here is a complete example:

from dataclasses import dataclass
from databrief.databrief import dump, load

@dataclass
class Example:
    a: int
    b: float
    c: bool
    d: bool
    e: bool
    f: bool
    g: bool
    h: bool
    i: bool
    j: bool
    k: bool
    l: float
    m: int
    n: int
    o: bool

example = Example(1, 2.0, True, False, True, False, True, False, True, True, False, 87543653.35197087, 1351346, -46583278, True)
serialized = dump(example)
deserialized = load(serialized, Example)
print(deserialized)

Contributing

Contributions are welcome! Please read our Contributing Guide for more information.

License

Databrief is distributed under the MIT license.

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

databrief-0.0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

databrief-0.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file databrief-0.0.1.tar.gz.

File metadata

  • Download URL: databrief-0.0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for databrief-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6883157fb186e0657b1165f0ad5c0005fd655f4772a942c13d0c31517f5c2a98
MD5 ab483892931cf59294be8d31cc83f75a
BLAKE2b-256 a0c3ae5cc97157e26f23fd46b8804c8c2529f1080d576d3676b125c199d0dcdd

See more details on using hashes here.

File details

Details for the file databrief-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: databrief-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for databrief-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db2ec06558877bdc5397ec6dbfd6a94a49dc76fcbd2ce2315ab56306ff46c3ef
MD5 7882c15e5208a3c2a93bc80185154a34
BLAKE2b-256 5e03520c72528821f81962145761c7af837b3401dd4189ec95076c419d5d6314

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