lodum.bson module provides BSON (Binary JSON) serialization and deserialization for lodum-enabled classes with support for streaming.
Installation
Requiresbson from pymongo. Install with:
Functions
dump
The object to encode.
Optional file-like object or Path to write to.
Additional arguments for
bson.encode.target is None, otherwise None.
Raises: ImportError if bson (pymongo) is not installed.
Note: BSON requires a dictionary at the root. If the object is not a dictionary, it will be wrapped in {"_v": obj}.
Example:
dumps
dump(obj).
The object to encode.
Additional arguments for
bson.encode.load
The class to instantiate.
BSON bytes, file-like object, or Path.
Maximum allowed size for bytes input.
cls.
Raises:
ImportErrorifbson(pymongo) is not installed.DeserializationErrorif the input is invalid or exceedsmax_size.
_v key (from wrapping), it will be automatically unwrapped.
Example:
loads
load(cls, source).
The class to instantiate.
BSON bytes to parse.
Additional arguments (e.g.,
max_size).cls.
stream
The class to instantiate for each item.
A binary stream, file-like object, or Path.
cls.
Raises:
ImportErrorifbson(pymongo) is not installed.DeserializationErrorif the source type is unsupported for streaming.
Notes
- BSON is the binary format used by MongoDB
- BSON requires a dictionary at the root level, so non-dict objects are wrapped
- The
decode_file_iterfunction handles concatenated BSON documents efficiently - Native bytes support without base64 encoding