Skip to content

Commit a5c0db6

Browse files
authored
PYTHON-4589 - Add async API docs (mongodb#1755)
1 parent 98658cf commit a5c0db6

33 files changed

+285
-47
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:mod:`change_stream` -- Watch changes on a collection, database, or cluster
2+
===========================================================================
3+
4+
.. automodule:: pymongo.asynchronous.change_stream
5+
:members:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:mod:`client_session` -- Logical sessions for sequential operations
2+
===================================================================
3+
4+
.. automodule:: pymongo.asynchronous.client_session
5+
:members:
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
:mod:`collection` -- Collection level operations
2+
================================================
3+
4+
.. automodule:: pymongo.asynchronous.collection
5+
:synopsis: Collection level operations
6+
7+
.. autoclass:: pymongo.asynchronous.collection.ReturnDocument
8+
9+
.. autoclass:: pymongo.asynchronous.collection.AsyncCollection(database, name, create=False, **kwargs)
10+
11+
.. describe:: c[name] || c.name
12+
13+
Get the `name` sub-collection of :class:`AsyncCollection` `c`.
14+
15+
Raises :class:`~pymongo.asynchronous.errors.InvalidName` if an invalid
16+
collection name is used.
17+
18+
.. autoattribute:: full_name
19+
.. autoattribute:: name
20+
.. autoattribute:: database
21+
.. autoattribute:: codec_options
22+
.. autoattribute:: read_preference
23+
.. autoattribute:: write_concern
24+
.. autoattribute:: read_concern
25+
.. automethod:: with_options
26+
.. automethod:: bulk_write
27+
.. automethod:: insert_one
28+
.. automethod:: insert_many
29+
.. automethod:: replace_one
30+
.. automethod:: update_one
31+
.. automethod:: update_many
32+
.. automethod:: delete_one
33+
.. automethod:: delete_many
34+
.. automethod:: aggregate
35+
.. automethod:: aggregate_raw_batches
36+
.. automethod:: watch
37+
.. automethod:: find(filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, batch_size=0, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None, session=None, allow_disk_use=None)
38+
.. automethod:: find_raw_batches(filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, batch_size=0, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None, session=None, allow_disk_use=None)
39+
.. automethod:: find_one(filter=None, *args, **kwargs)
40+
.. automethod:: find_one_and_delete
41+
.. automethod:: find_one_and_replace(filter, replacement, projection=None, sort=None, return_document=ReturnDocument.BEFORE, hint=None, session=None, **kwargs)
42+
.. automethod:: find_one_and_update(filter, update, projection=None, sort=None, return_document=ReturnDocument.BEFORE, array_filters=None, hint=None, session=None, **kwargs)
43+
.. automethod:: count_documents
44+
.. automethod:: estimated_document_count
45+
.. automethod:: distinct
46+
.. automethod:: create_index
47+
.. automethod:: create_indexes
48+
.. automethod:: drop_index
49+
.. automethod:: drop_indexes
50+
.. automethod:: list_indexes
51+
.. automethod:: index_information
52+
.. automethod:: create_search_index
53+
.. automethod:: create_search_indexes
54+
.. automethod:: drop_search_index
55+
.. automethod:: list_search_indexes
56+
.. automethod:: update_search_index
57+
.. automethod:: drop
58+
.. automethod:: rename
59+
.. automethod:: options
60+
.. automethod:: __getitem__
61+
.. automethod:: __getattr__
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:mod:`command_cursor` -- Tools for iterating over MongoDB command results
2+
=========================================================================
3+
4+
.. automodule:: pymongo.asynchronous.command_cursor
5+
:synopsis: Tools for iterating over MongoDB command results
6+
:members:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
:mod:`cursor` -- Tools for iterating over MongoDB query results
2+
===============================================================
3+
4+
.. automodule:: pymongo.asynchronous.cursor
5+
:synopsis: Tools for iterating over MongoDB query results
6+
7+
.. autoclass:: pymongo.asynchronous.cursor.AsyncCursor(collection, filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, batch_size=0, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None, session=None, allow_disk_use=None)
8+
:members:
9+
10+
.. describe:: c[index]
11+
12+
See :meth:`__getitem__` and read the warning.
13+
14+
.. automethod:: __getitem__
15+
16+
.. autoclass:: pymongo.asynchronous.cursor.AsyncRawBatchCursor(collection, filter=None, projection=None, skip=0, limit=0, no_cursor_timeout=False, cursor_type=CursorType.NON_TAILABLE, sort=None, allow_partial_results=False, oplog_replay=False, batch_size=0, collation=None, hint=None, max_scan=None, max_time_ms=None, max=None, min=None, return_key=False, show_record_id=False, snapshot=False, comment=None, allow_disk_use=None)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
:mod:`database` -- Database level operations
2+
============================================
3+
4+
.. automodule:: pymongo.asynchronous.database
5+
:synopsis: Database level operations
6+
7+
.. autoclass:: pymongo.asynchronous.database.AsyncDatabase
8+
:members:
9+
10+
.. describe:: db[collection_name] || db.collection_name
11+
12+
Get the `collection_name` :class:`~pymongo.asynchronous.collection.AsyncCollection` of
13+
:class:`AsyncDatabase` `db`.
14+
15+
Raises :class:`~pymongo.errors.InvalidName` if an invalid collection
16+
name is used.
17+
18+
.. note:: Use dictionary style access if `collection_name` is an
19+
attribute of the :class:`AsyncDatabase` class eg: db[`collection_name`].
20+
21+
.. automethod:: __getitem__
22+
.. automethod:: __getattr__
23+
.. autoattribute:: codec_options
24+
.. autoattribute:: read_preference
25+
.. autoattribute:: write_concern
26+
.. autoattribute:: read_concern
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
:mod:`pymongo async` -- Async Python driver for MongoDB
2+
=======================================================
3+
4+
.. automodule:: pymongo.asynchronous
5+
:synopsis: Asynchronous Python driver for MongoDB
6+
7+
.. data:: AsyncMongoClient
8+
9+
Alias for :class:`pymongo.asynchronous.mongo_client.MongoClient`.
10+
11+
Sub-modules:
12+
13+
.. toctree::
14+
:maxdepth: 2
15+
16+
change_stream
17+
client_session
18+
collection
19+
command_cursor
20+
cursor
21+
database
22+
mongo_client
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
:mod:`mongo_client` -- Tools for connecting to MongoDB
2+
======================================================
3+
4+
.. automodule:: pymongo.asynchronous.mongo_client
5+
:synopsis: Tools for connecting to MongoDB
6+
7+
.. autoclass:: pymongo.asynchronous.mongo_client.AsyncMongoClient(host='localhost', port=27017, document_class=dict, tz_aware=False, connect=True, **kwargs)
8+
9+
.. automethod:: aclose
10+
11+
.. describe:: c[db_name] || c.db_name
12+
13+
Get the `db_name` :class:`~pymongo.asynchronous.database.AsyncDatabase` on :class:`AsyncMongoClient` `c`.
14+
15+
Raises :class:`~pymongo.errors.InvalidName` if an invalid database name is used.
16+
17+
.. autoattribute:: topology_description
18+
.. autoattribute:: address
19+
.. autoattribute:: primary
20+
.. autoattribute:: secondaries
21+
.. autoattribute:: arbiters
22+
.. autoattribute:: is_primary
23+
.. autoattribute:: is_mongos
24+
.. autoattribute:: nodes
25+
.. autoattribute:: codec_options
26+
.. autoattribute:: read_preference
27+
.. autoattribute:: write_concern
28+
.. autoattribute:: read_concern
29+
.. autoattribute:: options
30+
.. automethod:: start_session
31+
.. automethod:: list_databases
32+
.. automethod:: list_database_names
33+
.. automethod:: drop_database
34+
.. automethod:: get_default_database
35+
.. automethod:: get_database
36+
.. automethod:: server_info
37+
.. automethod:: watch
38+
.. automethod:: __getitem__
39+
.. automethod:: __getattr__

doc/api/pymongo/index.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
Alias for :class:`pymongo.mongo_client.MongoClient`.
1111

12+
.. data:: AsyncMongoClient
13+
14+
Alias for :class:`pymongo.asynchronous.mongo_client.AsyncMongoClient`.
15+
1216
.. data:: ReadPreference
1317

1418
Alias for :class:`pymongo.read_preferences.ReadPreference`.
@@ -27,8 +31,9 @@
2731
Sub-modules:
2832

2933
.. toctree::
30-
:maxdepth: 2
34+
:maxdepth: 3
3135

36+
asynchronous/index
3237
auth_oidc
3338
change_stream
3439
client_options

pymongo/asynchronous/change_stream.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _resumable(exc: PyMongoError) -> bool:
8787
return False
8888

8989

90-
class ChangeStream(Generic[_DocumentType]):
90+
class AsyncChangeStream(Generic[_DocumentType]):
9191
"""The internal abstract base class for change stream cursors.
9292
9393
Should not be called directly by application developers. Use
@@ -276,7 +276,7 @@ async def close(self) -> None:
276276
self._closed = True
277277
await self._cursor.close()
278278

279-
def __aiter__(self) -> ChangeStream[_DocumentType]:
279+
def __aiter__(self) -> AsyncChangeStream[_DocumentType]:
280280
return self
281281

282282
@property
@@ -436,14 +436,14 @@ async def try_next(self) -> Optional[_DocumentType]:
436436
return _bson_to_dict(change.raw, self._orig_codec_options)
437437
return change
438438

439-
async def __aenter__(self) -> ChangeStream[_DocumentType]:
439+
async def __aenter__(self) -> AsyncChangeStream[_DocumentType]:
440440
return self
441441

442442
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
443443
await self.close()
444444

445445

446-
class CollectionChangeStream(ChangeStream[_DocumentType]):
446+
class AsyncCollectionChangeStream(AsyncChangeStream[_DocumentType]):
447447
"""A change stream that watches changes on a single collection.
448448
449449
Should not be called directly by application developers. Use
@@ -463,7 +463,7 @@ def _client(self) -> AsyncMongoClient[_DocumentType]:
463463
return self._target.database.client
464464

465465

466-
class DatabaseChangeStream(ChangeStream[_DocumentType]):
466+
class AsyncDatabaseChangeStream(AsyncChangeStream[_DocumentType]):
467467
"""A change stream that watches changes on all collections in a database.
468468
469469
Should not be called directly by application developers. Use
@@ -483,7 +483,7 @@ def _client(self) -> AsyncMongoClient[_DocumentType]:
483483
return self._target.client
484484

485485

486-
class ClusterChangeStream(DatabaseChangeStream[_DocumentType]):
486+
class AsyncClusterChangeStream(AsyncDatabaseChangeStream[_DocumentType]):
487487
"""A change stream that watches changes on all collections in the cluster.
488488
489489
Should not be called directly by application developers. Use

0 commit comments

Comments
 (0)