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.dev1.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.dev1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: databrief-0.0.1.dev1.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.dev1.tar.gz
Algorithm Hash digest
SHA256 d1ab46497098f45d4cf4f041a5b304920d09a54bc1cb1f8f7d103ea189596e60
MD5 a68b61b21f09c5b17eec25e526123404
BLAKE2b-256 796d532457afff744cb5373b99d8a40e4e873c6518418d084166ddf9e35cb38e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: databrief-0.0.1.dev1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 0873481adff3f86b2051d65a19a3220d9d5554bebb01ee81fd5ca0ee9192c8af
MD5 a4953cbae2ace07a7094de1a953c66cd
BLAKE2b-256 e30f41a82d9bcf07128f73e439a6cd40e93b553fb9f3266fb46627564f98a214

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