Databrief
databrief is a Python library for serializing dataclasses to bytes and deserializing bytes back to dataclasses.
Features
- Compact serialization
- Supports the following field types:
- Primitive types:
int,float,bool,str - Collections:
list,set,tuple,dict - Nested dataclasses
- Primitive types:
Installation
pip install databrief
Usage
Dumping a Dataclass to Bytes
To serialize a dataclass instance to bytes with specific integer and floating point sizes, 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, 4, 8) # int32 and fp64
print(serialized)
Loading Bytes to a Dataclass
To deserialize bytes back to a dataclass instance with given integer and floating point sizes, use the load function:
from databrief import load
deserialized = load(serialized, TestData, 4, 8) # int32 and fp64
print(deserialized)
Examples
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, 4, 8)
deserialized = load(serialized, Example, 4, 8)
print(deserialized)
Here is another example:
from dataclasses import dataclass
from databrief import dump, load
@dataclass
class InnerData:
x: int
y: str
@dataclass
class OuterData:
a: int
b: InnerData
c: bool
example = OuterData(a=1, b=InnerData(x=42, y="hello"), c=True)
serialized = dump(example, 4, 8)
deserialized = load(serialized, OuterData, 4, 8)
print(deserialized)
Contributing
Code Style and Static Type Checking
Run style checker.
flake8 ./databrief
Run static type checker.
mypy --strict databrief
Unit and Documentation Testing
Run unit tests.
python -m unittest
License
Databrief is distributed under the MIT license.
Metadata
Release files for databrief 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| databrief-0.1.1.tar.gz | 7.0 kB | Without provenance | Details for databrief-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| databrief-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for databrief-0.1.1-py3-none-any.whl |
Total release size: 13.6 kB
Release files / databrief-0.1.1.tar.gz
| Download URL | databrief-0.1.1.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9558e788afa88f18365f506b8da1a945cf38969f9fbfe6ecbe0709f7a2222dbf
|
|
BLAKE2b-256 checksum How to use checksums |
bab4b344d8e4d1161db7a15d4a11ff8f207fa93b12fb14125dc59f179ef7c648
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.5
|
Release files / databrief-0.1.1-py3-none-any.whl
| Download URL | databrief-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f1948359c0bf7a5d48c1b9112a1c59e30873cfdc329bbe9b7b2287a9b26edc6e
|
|
BLAKE2b-256 checksum How to use checksums |
55854e98d683fe6ac516a0a52ea5cd1ce90cc48f9d3c848bbf412f8bf6c31067
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.5
|
Security for databrief 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.