Skip to content

Commit c6995df

Browse files
authored
feat: add MongoDB client metadata (#27)
1 parent f58078c commit c6995df

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

pymongosql/connection.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
# -*- coding: utf-8 -*-
22
import logging
3+
from importlib.metadata import version as _get_version
34
from typing import Any, Optional, Sequence, Type, Union
45

56
from bson.codec_options import TypeRegistry
67
from pymongo import MongoClient
78
from pymongo.client_session import ClientSession
89
from pymongo.collection import Collection
910
from pymongo.database import Database
11+
from pymongo.driver_info import DriverInfo
1012
from pymongo.errors import ConnectionFailure
1113

14+
try:
15+
_VERSION = _get_version("pymongosql")
16+
except Exception:
17+
_VERSION = None
18+
19+
_DRIVER_INFO = DriverInfo(name="PyMongoSQL", version=_VERSION)
20+
1221
from .common import BaseCursor
1322
from .cursor import Cursor
1423
from .error import DatabaseError, OperationalError
@@ -87,6 +96,10 @@ def __init__(
8796
if type_registry is not None:
8897
self._pymongo_params["type_registry"] = type_registry
8998

99+
# Inject MongoDB client metadata so the handshake identifies this library
100+
if "driver" not in self._pymongo_params:
101+
self._pymongo_params["driver"] = _DRIVER_INFO
102+
90103
# Connection state
91104
self._autocommit = True
92105
self._in_transaction = False

0 commit comments

Comments
 (0)