Skip to content

Commit a4645f0

Browse files
authored
PYTHON-4712 Improve BSON encoding/decoding docs (mongodb#1823)
1 parent e6b95f6 commit a4645f0

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

bson/__init__.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,46 @@
2222
None null both
2323
bool boolean both
2424
int [#int]_ int32 / int64 py -> bson
25-
`bson.int64.Int64` int64 both
25+
:class:`bson.int64.Int64` int64 both
2626
float number (real) both
2727
str string both
2828
list array both
29-
dict / `SON` object both
30-
datetime.datetime [#dt]_ [#dt2]_ date both
31-
`bson.regex.Regex` regex both
29+
dict object both
30+
:class:`~bson.son.SON` object both
31+
:py:class:`~collections.abc.Mapping` object py -> bson
32+
:class:`~bson.raw_bson.RawBSONDocument` object both [#raw]_
33+
datetime.datetime [#dt]_ [#dt2]_ UTC datetime both
34+
:class:`~bson.datetime_ms.DatetimeMS` UTC datetime both [#dt3]_
35+
:class:`~bson.regex.Regex` regex both
3236
compiled re [#re]_ regex py -> bson
33-
`bson.binary.Binary` binary both
34-
`bson.objectid.ObjectId` oid both
35-
`bson.dbref.DBRef` dbref both
37+
:class:`~bson.binary.Binary` binary both
38+
:py:class:`uuid.UUID` [#uuid]_ binary both
39+
:class:`~bson.objectid.ObjectId` oid both
40+
:class:`~bson.dbref.DBRef` dbref both
41+
:class:`~bson.dbref.DBRef` dbpointer bson -> py
3642
None undefined bson -> py
37-
`bson.code.Code` code both
43+
:class:`~bson.code.Code` code both
3844
str symbol bson -> py
3945
bytes [#bytes]_ binary both
46+
:class:`~bson.timestamp.Timestamp` timestamp both
47+
:class:`~bson.decimal128.Decimal128` decimal128 both
48+
:class:`~bson.min_key.MinKey` min key both
49+
:class:`~bson.max_key.MaxKey` max key both
4050
======================================= ============= ===================
4151
4252
.. [#int] A Python int will be saved as a BSON int32 or BSON int64 depending
4353
on its size. A BSON int32 will always decode to a Python int. A BSON
4454
int64 will always decode to a :class:`~bson.int64.Int64`.
45-
.. [#dt] datetime.datetime instances will be rounded to the nearest
46-
millisecond when saved
47-
.. [#dt2] all datetime.datetime instances are treated as *naive*. clients
48-
should always use UTC.
55+
.. [#raw] Decoding a bson object to :class:`~bson.raw_bson.RawBSONDocument` can be
56+
optionally configured via :attr:`~bson.codec_options.CodecOptions.document_class`.
57+
.. [#dt] datetime.datetime instances are encoded with millisecond precision so
58+
the microsecond field is truncated.
59+
.. [#dt2] all datetime.datetime instances are encoded as UTC. By default, they
60+
are decoded as *naive* but timezone aware datetimes are also supported.
61+
See :doc:`/examples/datetimes` for examples.
62+
.. [#dt3] To enable decoding a bson UTC datetime to a :class:`~bson.datetime_ms.DatetimeMS`
63+
instance see :ref:`handling-out-of-range-datetimes`.
64+
.. [#uuid] For :py:class:`uuid.UUID` encoding and decoding behavior see :doc:`/examples/uuid`.
4965
.. [#re] :class:`~bson.regex.Regex` instances and regular expression
5066
objects from ``re.compile()`` are both saved as BSON regular expressions.
5167
BSON regular expressions are decoded as :class:`~bson.regex.Regex`

0 commit comments

Comments
 (0)