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.dev2.tar.gz (4.1 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.dev2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: databrief-0.0.1.dev2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for databrief-0.0.1.dev2.tar.gz
Algorithm Hash digest
SHA256 a1b6fda78c25227bd227cfeb15f9463ea84b4dd63f5173ba8102bda697e8b908
MD5 23df53b61114b8b554194f6ad19b7139
BLAKE2b-256 16836025920b505cbe288e3b2f32a1eebcc6795d860c23efc9aa03a2cf714ccd

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for databrief-0.0.1.dev2-py3-none-any.whl
Algorithm Hash digest
SHA256 853cac39a895cf18d3eafa031366ebaa13b5a350f96ab00f0b6591cc06fd9918
MD5 aaa5d14d29eb772126e543d42eb472e0
BLAKE2b-256 1df4f50a769017184787324337188198adba1a5f3204f80e9977735cf9bc151f

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