Skip to content

Commit 9c31bed

Browse files
DOCSP-36985 network compression (#8)
1 parent 3e65387 commit 9c31bed

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed
Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,83 @@
11
.. uses network-compression.rst, installation.rst
22

33
.. _network-compression-example:
4+
.. _pymongo-network-compression:
45

6+
===================
57
Network Compression
68
===================
79

8-
PyMongo supports network compression where network traffic between the client
9-
and MongoDB server are compressed which reduces the amount of data passed
10-
over the network. By default no compression is used.
10+
.. contents:: On this page
11+
:local:
12+
:backlinks: none
13+
:depth: 1
14+
:class: singlecol
15+
16+
.. facet::
17+
:name: genre
18+
:values: reference
19+
20+
.. meta::
21+
:keywords: wire protocol
22+
23+
{+driver-short+} supports network compression, which compresses network traffic
24+
between the client and the MongoDB server, and reduces the amount of data passed
25+
over the network. By default, {+driver-short+} doesn't use any compression.
1126

1227
The driver supports the following algorithms:
1328

14-
- `snappy <https://pypi.org/project/python-snappy>`_ available in MongoDB 3.4 and later.
29+
- `snappy <https://pypi.org/project/python-snappy>`__, available in MongoDB 3.4 and later.
1530
- ``zlib`` available in MongoDB 3.6 and later.
16-
- `zstandard <https://pypi.org/project/zstandard/>`_ available in MongoDB 4.2 and later.
31+
- `zstandard <https://pypi.org/project/zstandard/>`__, available in MongoDB 4.2 and later.
1732

1833
Wire protocol compression with snappy requires `python-snappy
19-
<https://pypi.org/project/python-snappy>`_:
34+
<https://pypi.org/project/python-snappy>`__:
2035

2136
.. code-block:: python
2237

23-
$ python3 -m pip install "pymongo[snappy]"
38+
$ python3 -m pip install "pymongo[snappy]"
2439

2540
Wire protocol compression with zstandard requires `zstandard
26-
<https://pypi.org/project/zstandard>`_:
41+
<https://pypi.org/project/zstandard>`__:
2742

2843
.. code-block:: python
2944

30-
$ python3 -m pip install "pymongo[zstd]"
45+
$ python3 -m pip install "pymongo[zstd]"
46+
47+
Specify Compression Algorithms
48+
------------------------------
3149

32-
Applications can enable wire protocol compression via the ``compressors`` URI and
33-
keyword argument to the ``~pymongo.mongo_client.MongoClient`` method. For example:
50+
You can enable wire protocol compression when you're instantiating a
51+
``MongoClient`` by specifying the algorithm name in
52+
the ``compressors`` option. For example:
3453

3554
.. code-block:: python
3655

3756
>>> client = MongoClient(compressors='zlib')
3857

39-
When multiple compression algorithms are given, the driver selects the first one in the
40-
list supported by the MongoDB instance to which it is connected. For example:
58+
When you specify multiple compression algorithms, the driver selects the first one in the
59+
list supported by the MongoDB instance it's connected to. For example:
4160

4261
.. code-block:: python
4362

44-
>>> client = MongoClient(compressors='snappy,zstandard,zlib')
63+
>>> client = MongoClient(compressors='snappy,zstandard,zlib')
4564

46-
The ``compressors`` option can also be set via the URI:
65+
You can also set the ``compressors`` option in the connection URI:
4766

4867
.. code-block:: python
4968

50-
>>> client = MongoClient('mongodb://example.com/?compressors=snappy,zstandard,zlib')
69+
>>> client = MongoClient('mongodb://example.com/?compressors=snappy,zstandard,zlib')
5170

52-
Additionally, zlib compression allows specifying a compression level with supported values from -1 to 9:
71+
Additionally, ``zlib`` compression allows specifying a compression level with supported values from -1 to 9:
5372

5473
.. code-block:: python
5574

56-
>>> client = MongoClient(compressors='zlib', zlibCompressionLevel=-1)
75+
>>> client = MongoClient(compressors='zlib', zlibCompressionLevel=-1)
76+
77+
Pass the ``zlibCompressionLevel`` as the ``level`` argument to ``zlib.compress``.
5778

58-
The ``zlibCompressionLevel`` is passed as the ``level`` argument to ``zlib.compress``.
79+
.. seealso::
5980

60-
.. seealso:: The MongoDB documentation on `network compression URI options <https://dochub.mongodb.org/core/compression-options>`_.
81+
To learn more about network compression URI options, see the
82+
:manual:`Compression Options </reference/connection-string/#compression-options>`
83+
section on the Server manual.

0 commit comments

Comments
 (0)