3333 from requests .models import Response
3434
3535
36+ from .about import __version__ as VERSION
3637from .assetattachments import _AssetAttachmentsClient
3738from .assets import _AssetsPublic
3839from .confirmer import MAX_TIME
3940from .constants import (
4041 HEADERS_REQUEST_TOTAL_COUNT ,
4142 HEADERS_TOTAL_COUNT ,
43+ PARTNER_ID ,
44+ USER_AGENT ,
45+ USER_AGENT_PREFIX ,
4246)
4347from .dictmerge import _deepmerge , _dotdict
4448from .errors import (
@@ -82,12 +86,16 @@ def __init__(
8286 fixtures : "dict[str, Any]|None" = None ,
8387 verify : bool = True ,
8488 max_time : float = MAX_TIME ,
89+ partner_id : str = "" ,
90+ user_agent : str = "" ,
8591 ):
8692 self ._verify = verify
8793 self ._response_ring_buffer = deque (maxlen = self .RING_BUFFER_MAX_LEN )
8894 self ._session = None
8995 self ._max_time = max_time
9096 self ._fixtures = fixtures or {}
97+ self ._partner_id = partner_id
98+ self ._user_agent = user_agent
9199
92100 # Type hints for IDE autocomplete, keep in sync with CLIENTS map above
93101 self .assets : _AssetsPublic
@@ -151,6 +159,21 @@ def max_time(self) -> float:
151159 """bool: Returns maximum time in seconds to wait for confirmation"""
152160 return self ._max_time
153161
162+ @property
163+ def version (self ) -> str :
164+ """str: Returns version of the archivist package"""
165+ return VERSION
166+
167+ @property
168+ def partner_id (self ) -> str :
169+ """str: Returns partner id if set when initialising an instance of this class"""
170+ return self ._partner_id
171+
172+ @property
173+ def user_agent (self ) -> str :
174+ """str: Returns partner id if set when initialising an instance of this class"""
175+ return self ._user_agent
176+
154177 @property
155178 def fixtures (self ) -> "dict[str, Any]" :
156179 """dict: Contains predefined attributes for each endpoint"""
@@ -170,6 +193,18 @@ def __copy__(self):
170193
171194 def _add_headers (self , headers : "dict[str, str]|None" ) -> "dict[str, str]" :
172195 newheaders = {** headers } if headers is not None else {}
196+ u = self .user_agent
197+ if u :
198+ newheaders [USER_AGENT ] = (
199+ f"{ self .user_agent } "
200+ f"{ USER_AGENT_PREFIX } { self .version } "
201+ )
202+ else :
203+ newheaders [USER_AGENT ] = f"{ USER_AGENT_PREFIX } { self .version } "
204+
205+ p = self .partner_id
206+ if p :
207+ newheaders [PARTNER_ID ] = p
173208
174209 return newheaders
175210
0 commit comments