codec_options
– Tools for specifying BSON codec options
class bson.codec_options.CodecOptions
Encapsulates options used encoding and / or decoding BSON.
The document_class option is used to define a custom type for use decoding BSON documents. Access to the underlying raw BSON bytes for a document is available using the RawBSONDocument type:
The document class can be any type that inherits from MutableMapping
:
See for examples using the tz_aware and tzinfo options.
See UUIDLegacy for examples using the uuid_representation option.
New in version 3.8: type_registry attribute.
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:
class
Base class for defining type codec classes which describe how a custom type can be transformed to/from one of the types can already encode/decode.
Codec classes must implement the python_type
attribute, and the transform_python
method to support encoding, as well as the bson_type
attribute, and the transform_bson
method to support decoding.
See The TypeCodec Class documentation for an example.
class bson.codec_options.TypeDecoder
Base class for defining type codec classes which describe how a BSON type can be transformed to a custom type.
Codec classes must implement the bson_type
attribute, and the transform_bson
method to support decoding.
See documentation for an example.
transform_bson
(value)
class bson.codec_options.TypeEncoder
Base class for defining type codec classes which describe how a custom type can be transformed to one of the types BSON understands.
Codec classes must implement the python_type
attribute, and the transform_python
method to support encoding.
See The TypeCodec Class documentation for an example.
python_type
The Python type to be converted into something serializable.
transform_python
(value)Convert the given Python object into something serializable.
class bson.codec_options.TypeRegistry
(type_codecs=None, fallback_encoder=None)
Encapsulates type codecs used in encoding and / or decoding BSON, as well as the fallback encoder. Type registries cannot be modified after instantiation.
can be initialized with an iterable of type codecs, and a callable for the fallback encoder:
Parameters: |
|
---|