Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

avoine

A tiny serialisation and deserialisation library.

avoine does not implement any serialisation or deserialisation itself. Instead, it relies on the common Python pattern of load and dump functions (for file-like objects) and loads and dumps functions (for string-like objects).

To configure serialisation and deserialisation, use the avoine class:

import json
import tomllib

from avoine import avoine

# define a format for deserialisation (load -> from file, loads -> from string/bytes)
# and serialisation (dump -> from file, dumps -> from string/bytes) and set it as default
avoine.register("json", default=True, load=json.load, loads=json.loads, dump=json.dump, dumps=json.dumps)

# not all methods are required
avoine.register("toml", load=tomllib.load)

# register can be used again to update a format definition
avoine.register("toml", loads=tomllib.loads)

# the default format is what is used when the format is left unspecified
# it can be set or unset on its own
avoine.default = "toml"
avoine.default = None

# and retrieved with
print(avoine.default)

# you can unregister a format too
avoine.unregister("toml", default="json")

# the list of currently-registered formats can be retrieved with
avoine.formats()

# or for a specific method with
avoine.formats("load")

# all configuration can be reset with
avoine.clear()

Then, in your code, you can define dataclasses and add the AvoineBase mixin class, which will allow you to serialise/deserialise them from any registered format anywhere:

from dataclasses import dataclass
from avoine import AvoineBase

@dataclass
class MyStruct(AvoineBase):
    foo: str
    bar: MyInnerStruct

@dataclass
class MyInnerStruct(AvoineBase):
    baz: list[str]
    opt: str | None = None

with open("mystruct.json") as f:
    data = MyStruct.load(f)
    # kwargs for the underlying loader/dumper are passed down to them
    data.dumps(indent=2)

with open("mystruct.toml") as f:
    print(MyStruct.load(f, format="toml"))

Custom formats can be created by writing functions with the following signatures:

def load(fp: SupportsRead[AnyStr], **kwargs) -> dict[str, Any]:
    ...

def loads(s: AnyStr, **kwargs) -> dict[str, Any]:
    ...

def dump(obj: Any, fp: SupportsWrite[AnyStr], **kwargs) -> None:
    ...

def dumps(obj: Any, **kwargs) -> AnyStr:
    ...

Notes:

  • AnyStr can be str, bytes, or both
  • kwargs are optional

If a set of loading/dumping functions for a format do not match these signatures, wrapper functions can be written to transform them to a compatible signature.

License

avoine is in the public domain.

To the extent possible under law, classabbyamp has waived all copyright and related or neighboring rights to this work.

http://creativecommons.org/publicdomain/zero/1.0/

Metadata

Release files for avoine 0.1.0a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for avoine 0.1.0a2
File Size Uploaded Provenance Actions
avoine-0.1.0a2.tar.gz 4.8 kB Without provenance Details for avoine-0.1.0a2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for avoine 0.1.0a2
File Interpreter ABI Platform Actions
avoine-0.1.0a2-py3-none-any.whl Python 3 none any Details for avoine-0.1.0a2-py3-none-any.whl

Total release size: 10.4 kB

Release files / avoine-0.1.0a2.tar.gz

Download URL avoine-0.1.0a2.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
37cb13bb252a3778419ed123ed543deb1bec7776305f2922fc43085f88fe20f2
BLAKE2b-256 checksum
How to use checksums
4d05233baf62360796257b394c90c8f6b6910df1d327d893295c8a8204582edf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Void","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / avoine-0.1.0a2-py3-none-any.whl

Download URL avoine-0.1.0a2-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
711924715e51c2c257087e8bbdd673871af4cadca94efd1ec9e2672c7de3c6d3
BLAKE2b-256 checksum
How to use checksums
b48b4c583c2afb9612d36192f985ec33c11aa4655a845d4d3deadd004abb88ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Void","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for avoine 0.1.0a2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page