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 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 import load

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

Example

Here is a complete example:

from dataclasses import dataclass
from 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.dev0.tar.gz (4.4 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.dev0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: databrief-0.0.1.dev0.tar.gz
  • Upload date:
  • Size: 4.4 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.dev0.tar.gz
Algorithm Hash digest
SHA256 53810ed80438c2743aee727ab3d0b51245112037b198c2be88285a76745d7aea
MD5 b5c040940c5ff947a775750b79860bf5
BLAKE2b-256 0a89003a7a4de30db531e810a9095baf4b0620be443b4fd4371d16e94206a885

See more details on using hashes here.

File details

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

File metadata

  • Download URL: databrief-0.0.1.dev0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 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.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 428f8da66f3c9428db596d01d2638c0ab09bd1c3063b4cca672dcf7aec53d852
MD5 41032f574699509f44fa655d06a8e570
BLAKE2b-256 4435cd21e55d898df2fe2da8905ab9d4bbea48271401613ab8e37a2130e1d7d3

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