5151)
5252from pymongo .collection import Collection
5353from pymongo .common import MAX_WRITE_BATCH_SIZE
54+ from pymongo .driver_info import DriverInfo
5455
56+ import pymongoarrow .version as pymongoarrow_version
5557from pymongoarrow .context import PyMongoArrowContext
5658from pymongoarrow .errors import ArrowWriteError
5759from pymongoarrow .result import ArrowWriteResult
9092_MAX_WRITE_BATCH_SIZE = max (100000 , MAX_WRITE_BATCH_SIZE )
9193
9294
95+ def _add_driver_metadata (collection : Collection ):
96+ client = collection .database .client
97+
98+ if callable (client .append_metadata ):
99+ client .append_metadata (
100+ DriverInfo (name = "PyMongoArrow" , version = pymongoarrow_version .__version__ )
101+ )
102+
103+
93104def find_arrow_all (collection , query , * , schema = None , allow_invalid = False , ** kwargs ):
94105 """Method that returns the results of a find query as a
95106 :class:`pyarrow.Table` instance.
@@ -110,6 +121,7 @@ def find_arrow_all(collection, query, *, schema=None, allow_invalid=False, **kwa
110121 :Returns:
111122 An instance of class:`pyarrow.Table`.
112123 """
124+ _add_driver_metadata (collection )
113125 context = PyMongoArrowContext (
114126 schema , codec_options = collection .codec_options , allow_invalid = allow_invalid
115127 )
@@ -152,6 +164,7 @@ def aggregate_arrow_all(collection, pipeline, *, schema=None, allow_invalid=Fals
152164 :Returns:
153165 An instance of class:`pyarrow.Table`.
154166 """
167+ _add_driver_metadata (collection )
155168 context = PyMongoArrowContext (
156169 schema , codec_options = collection .codec_options , allow_invalid = allow_invalid
157170 )
@@ -570,6 +583,7 @@ def write(
570583 else :
571584 type_registry = TypeRegistry ([* base_codecs , _DecimalCodec ()])
572585 codec_options = codec_options .with_options (type_registry = type_registry )
586+ _add_driver_metadata (collection )
573587
574588 while cur_offset < tab_size :
575589 cur_size = 0
0 commit comments