raw_bson – Tools for representing raw BSON documents.¶
Tools for representing raw BSON documents.
-
bson.raw_bson.DEFAULT_RAW_BSON_OPTIONS= CodecOptions(document_class=<class 'bson.raw_bson.RawBSONDocument'>, tz_aware=False, uuid_representation=UuidRepresentation.PYTHON_LEGACY, unicode_decode_error_handler='strict', tzinfo=None, type_registry=TypeRegistry(type_codecs=[], fallback_encoder=None))¶ The default
CodecOptionsforRawBSONDocument.
-
class
bson.raw_bson.RawBSONDocument(bson_bytes, codec_options=None)¶ Create a new
RawBSONDocumentRawBSONDocumentis a representation of a BSON document that provides access to the underlying raw BSON bytes. Only when a field is accessed or modified within the document does RawBSONDocument decode its bytes.RawBSONDocumentimplements theMappingabstract base class from the standard library so it can be used like a read-onlydict:>>> from bson import encode >>> raw_doc = RawBSONDocument(encode({'_id': 'my_doc'})) >>> raw_doc.raw b'...' >>> raw_doc['_id'] 'my_doc'
- Parameters
bson_bytes: the BSON bytes that compose this document
codec_options (optional): An instance of
CodecOptionswhosedocument_classmust beRawBSONDocument. The default isDEFAULT_RAW_BSON_OPTIONS.
Changed in version 3.8:
RawBSONDocumentnow validates that thebson_bytespassed in represent a single bson document.Changed in version 3.5: If a
CodecOptionsis passed in, its document_class must beRawBSONDocument.-
items()¶ Lazily decode and iterate elements in this document.
-
property
raw¶ The raw BSON bytes composing this document.