codec_options
– Tools for specifying BSON codec options¶
Tools for specifying BSON codec options.
-
class
bson.codec_options.
CodecOptions
¶ Encapsulates BSON options used in CRUD operations.
Parameters: - document_class: BSON documents returned in queries will be decoded
to an instance of this class. Must be a subclass of
MutableMapping
. Defaults todict
. - tz_aware: If
True
, BSON datetimes will be decoded to timezone aware instances ofdatetime
. Otherwise they will be naive. Defaults toFalse
. - uuid_representation: The BSON representation to use when encoding
and decoding instances of
UUID
. Defaults toPYTHON_LEGACY
. - unicode_decode_error_handler: The error handler to use when decoding an invalid BSON string. Valid options include ‘strict’, ‘replace’, and ‘ignore’. Defaults to ‘strict’.
- tzinfo: A
tzinfo
subclass that specifies the timezone to/from whichdatetime
objects should be encoded/decoded.
Warning
Care must be taken when changing unicode_decode_error_handler from its default value (‘strict’). The ‘replace’ and ‘ignore’ modes should not be used when documents retrieved from the server will be modified in the client application and stored back to the server.
-
with_options
(**kwargs)¶ Make a copy of this CodecOptions, overriding some options:
>>> from bson.codec_options import DEFAULT_CODEC_OPTIONS >>> DEFAULT_CODEC_OPTIONS.tz_aware False >>> options = DEFAULT_CODEC_OPTIONS.with_options(tz_aware=True) >>> options.tz_aware True
New in version 3.5.
- document_class: BSON documents returned in queries will be decoded
to an instance of this class. Must be a subclass of