Skip to content

Commit 8d9696f

Browse files
fix(python): expose user_agent on the config (#4141) (generated) [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent abb8202 commit 8d9696f

File tree

39 files changed

+174
-84
lines changed

39 files changed

+174
-84
lines changed

clients/algoliasearch-client-python/algoliasearch/abtesting/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ async def set_client_api_key(self, api_key: str) -> None:
132132
"""Sets a new API key to authenticate requests."""
133133
self._transporter.config.set_client_api_key(api_key)
134134

135+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
136+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
137+
self._transporter.config.add_user_agent(segment, version)
138+
135139
async def add_ab_tests_with_http_info(
136140
self,
137141
add_ab_tests_request: Union[AddABTestsRequest, dict[str, Any]],
@@ -977,6 +981,10 @@ def set_client_api_key(self, api_key: str) -> None:
977981
"""Sets a new API key to authenticate requests."""
978982
self._transporter.config.set_client_api_key(api_key)
979983

984+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
985+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
986+
self._transporter.config.add_user_agent(segment, version)
987+
980988
def add_ab_tests_with_http_info(
981989
self,
982990
add_ab_tests_request: Union[AddABTestsRequest, dict[str, Any]],

clients/algoliasearch-client-python/algoliasearch/abtesting/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -15,7 +16,8 @@ def __init__(
1516
) -> None:
1617
super().__init__(app_id, api_key)
1718

18-
user_agent = UserAgent().add("Abtesting")
19+
self._user_agent = UserAgent()
20+
self.add_user_agent("Abtesting", __version__)
1921

2022
if app_id is None or not app_id:
2123
raise ValueError("`app_id` is missing.")
@@ -26,7 +28,7 @@ def __init__(
2628
self.headers = {
2729
"x-algolia-application-id": app_id,
2830
"x-algolia-api-key": api_key,
29-
"user-agent": user_agent.get(),
31+
"user-agent": self._user_agent.get(),
3032
"content-type": "application/json",
3133
}
3234

clients/algoliasearch-client-python/algoliasearch/analytics/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ async def set_client_api_key(self, api_key: str) -> None:
172172
"""Sets a new API key to authenticate requests."""
173173
self._transporter.config.set_client_api_key(api_key)
174174

175+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
176+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
177+
self._transporter.config.add_user_agent(segment, version)
178+
175179
async def custom_delete_with_http_info(
176180
self,
177181
path: Annotated[
@@ -3207,6 +3211,10 @@ def set_client_api_key(self, api_key: str) -> None:
32073211
"""Sets a new API key to authenticate requests."""
32083212
self._transporter.config.set_client_api_key(api_key)
32093213

3214+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
3215+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
3216+
self._transporter.config.add_user_agent(segment, version)
3217+
32103218
def custom_delete_with_http_info(
32113219
self,
32123220
path: Annotated[

clients/algoliasearch-client-python/algoliasearch/analytics/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -15,7 +16,8 @@ def __init__(
1516
) -> None:
1617
super().__init__(app_id, api_key)
1718

18-
user_agent = UserAgent().add("Analytics")
19+
self._user_agent = UserAgent()
20+
self.add_user_agent("Analytics", __version__)
1921

2022
if app_id is None or not app_id:
2123
raise ValueError("`app_id` is missing.")
@@ -26,7 +28,7 @@ def __init__(
2628
self.headers = {
2729
"x-algolia-application-id": app_id,
2830
"x-algolia-api-key": api_key,
29-
"user-agent": user_agent.get(),
31+
"user-agent": self._user_agent.get(),
3032
"content-type": "application/json",
3133
}
3234

clients/algoliasearch-client-python/algoliasearch/ingestion/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ async def set_client_api_key(self, api_key: str) -> None:
209209
"""Sets a new API key to authenticate requests."""
210210
self._transporter.config.set_client_api_key(api_key)
211211

212+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
213+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
214+
self._transporter.config.add_user_agent(segment, version)
215+
212216
async def create_authentication_with_http_info(
213217
self,
214218
authentication_create: Union[AuthenticationCreate, dict[str, Any]],
@@ -4933,6 +4937,10 @@ def set_client_api_key(self, api_key: str) -> None:
49334937
"""Sets a new API key to authenticate requests."""
49344938
self._transporter.config.set_client_api_key(api_key)
49354939

4940+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
4941+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
4942+
self._transporter.config.add_user_agent(segment, version)
4943+
49364944
def create_authentication_with_http_info(
49374945
self,
49384946
authentication_create: Union[AuthenticationCreate, dict[str, Any]],

clients/algoliasearch-client-python/algoliasearch/ingestion/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -12,7 +13,8 @@ def __init__(
1213
) -> None:
1314
super().__init__(app_id, api_key)
1415

15-
user_agent = UserAgent().add("Ingestion")
16+
self._user_agent = UserAgent()
17+
self.add_user_agent("Ingestion", __version__)
1618

1719
if app_id is None or not app_id:
1820
raise ValueError("`app_id` is missing.")
@@ -23,7 +25,7 @@ def __init__(
2325
self.headers = {
2426
"x-algolia-application-id": app_id,
2527
"x-algolia-api-key": api_key,
26-
"user-agent": user_agent.get(),
28+
"user-agent": self._user_agent.get(),
2729
"content-type": "application/json",
2830
}
2931

clients/algoliasearch-client-python/algoliasearch/insights/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ async def set_client_api_key(self, api_key: str) -> None:
118118
"""Sets a new API key to authenticate requests."""
119119
self._transporter.config.set_client_api_key(api_key)
120120

121+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
122+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
123+
self._transporter.config.add_user_agent(segment, version)
124+
121125
async def custom_delete_with_http_info(
122126
self,
123127
path: Annotated[
@@ -653,6 +657,10 @@ def set_client_api_key(self, api_key: str) -> None:
653657
"""Sets a new API key to authenticate requests."""
654658
self._transporter.config.set_client_api_key(api_key)
655659

660+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
661+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
662+
self._transporter.config.add_user_agent(segment, version)
663+
656664
def custom_delete_with_http_info(
657665
self,
658666
path: Annotated[

clients/algoliasearch-client-python/algoliasearch/insights/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -15,7 +16,8 @@ def __init__(
1516
) -> None:
1617
super().__init__(app_id, api_key)
1718

18-
user_agent = UserAgent().add("Insights")
19+
self._user_agent = UserAgent()
20+
self.add_user_agent("Insights", __version__)
1921

2022
if app_id is None or not app_id:
2123
raise ValueError("`app_id` is missing.")
@@ -26,7 +28,7 @@ def __init__(
2628
self.headers = {
2729
"x-algolia-application-id": app_id,
2830
"x-algolia-api-key": api_key,
29-
"user-agent": user_agent.get(),
31+
"user-agent": self._user_agent.get(),
3032
"content-type": "application/json",
3133
}
3234

clients/algoliasearch-client-python/algoliasearch/monitoring/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ async def set_client_api_key(self, api_key: str) -> None:
124124
"""Sets a new API key to authenticate requests."""
125125
self._transporter.config.set_client_api_key(api_key)
126126

127+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
128+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
129+
self._transporter.config.add_user_agent(segment, version)
130+
127131
async def custom_delete_with_http_info(
128132
self,
129133
path: Annotated[
@@ -995,6 +999,10 @@ def set_client_api_key(self, api_key: str) -> None:
995999
"""Sets a new API key to authenticate requests."""
9961000
self._transporter.config.set_client_api_key(api_key)
9971001

1002+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
1003+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
1004+
self._transporter.config.add_user_agent(segment, version)
1005+
9981006
def custom_delete_with_http_info(
9991007
self,
10001008
path: Annotated[

clients/algoliasearch-client-python/algoliasearch/monitoring/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -10,7 +11,8 @@ class MonitoringConfig(BaseConfig):
1011
def __init__(self, app_id: Optional[str], api_key: Optional[str]) -> None:
1112
super().__init__(app_id, api_key)
1213

13-
user_agent = UserAgent().add("Monitoring")
14+
self._user_agent = UserAgent()
15+
self.add_user_agent("Monitoring", __version__)
1416

1517
if app_id is None or not app_id:
1618
raise ValueError("`app_id` is missing.")
@@ -21,7 +23,7 @@ def __init__(self, app_id: Optional[str], api_key: Optional[str]) -> None:
2123
self.headers = {
2224
"x-algolia-application-id": app_id,
2325
"x-algolia-api-key": api_key,
24-
"user-agent": user_agent.get(),
26+
"user-agent": self._user_agent.get(),
2527
"content-type": "application/json",
2628
}
2729

clients/algoliasearch-client-python/algoliasearch/personalization/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ async def set_client_api_key(self, api_key: str) -> None:
128128
"""Sets a new API key to authenticate requests."""
129129
self._transporter.config.set_client_api_key(api_key)
130130

131+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
132+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
133+
self._transporter.config.add_user_agent(segment, version)
134+
131135
async def custom_delete_with_http_info(
132136
self,
133137
path: Annotated[
@@ -777,6 +781,10 @@ def set_client_api_key(self, api_key: str) -> None:
777781
"""Sets a new API key to authenticate requests."""
778782
self._transporter.config.set_client_api_key(api_key)
779783

784+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
785+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
786+
self._transporter.config.add_user_agent(segment, version)
787+
780788
def custom_delete_with_http_info(
781789
self,
782790
path: Annotated[

clients/algoliasearch-client-python/algoliasearch/personalization/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -12,7 +13,8 @@ def __init__(
1213
) -> None:
1314
super().__init__(app_id, api_key)
1415

15-
user_agent = UserAgent().add("Personalization")
16+
self._user_agent = UserAgent()
17+
self.add_user_agent("Personalization", __version__)
1618

1719
if app_id is None or not app_id:
1820
raise ValueError("`app_id` is missing.")
@@ -23,7 +25,7 @@ def __init__(
2325
self.headers = {
2426
"x-algolia-application-id": app_id,
2527
"x-algolia-api-key": api_key,
26-
"user-agent": user_agent.get(),
28+
"user-agent": self._user_agent.get(),
2729
"content-type": "application/json",
2830
}
2931

clients/algoliasearch-client-python/algoliasearch/query_suggestions/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ async def set_client_api_key(self, api_key: str) -> None:
126126
"""Sets a new API key to authenticate requests."""
127127
self._transporter.config.set_client_api_key(api_key)
128128

129+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
130+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
131+
self._transporter.config.add_user_agent(segment, version)
132+
129133
async def create_config_with_http_info(
130134
self,
131135
configuration_with_index: Union[ConfigurationWithIndex, dict[str, Any]],
@@ -941,6 +945,10 @@ def set_client_api_key(self, api_key: str) -> None:
941945
"""Sets a new API key to authenticate requests."""
942946
self._transporter.config.set_client_api_key(api_key)
943947

948+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
949+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
950+
self._transporter.config.add_user_agent(segment, version)
951+
944952
def create_config_with_http_info(
945953
self,
946954
configuration_with_index: Union[ConfigurationWithIndex, dict[str, Any]],

clients/algoliasearch-client-python/algoliasearch/query_suggestions/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -12,7 +13,8 @@ def __init__(
1213
) -> None:
1314
super().__init__(app_id, api_key)
1415

15-
user_agent = UserAgent().add("QuerySuggestions")
16+
self._user_agent = UserAgent()
17+
self.add_user_agent("QuerySuggestions", __version__)
1618

1719
if app_id is None or not app_id:
1820
raise ValueError("`app_id` is missing.")
@@ -23,7 +25,7 @@ def __init__(
2325
self.headers = {
2426
"x-algolia-application-id": app_id,
2527
"x-algolia-api-key": api_key,
26-
"user-agent": user_agent.get(),
28+
"user-agent": self._user_agent.get(),
2729
"content-type": "application/json",
2830
}
2931

clients/algoliasearch-client-python/algoliasearch/recommend/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ async def set_client_api_key(self, api_key: str) -> None:
135135
"""Sets a new API key to authenticate requests."""
136136
self._transporter.config.set_client_api_key(api_key)
137137

138+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
139+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
140+
self._transporter.config.add_user_agent(segment, version)
141+
138142
async def batch_recommend_rules_with_http_info(
139143
self,
140144
index_name: Annotated[
@@ -1115,6 +1119,10 @@ def set_client_api_key(self, api_key: str) -> None:
11151119
"""Sets a new API key to authenticate requests."""
11161120
self._transporter.config.set_client_api_key(api_key)
11171121

1122+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
1123+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
1124+
self._transporter.config.add_user_agent(segment, version)
1125+
11181126
def batch_recommend_rules_with_http_info(
11191127
self,
11201128
index_name: Annotated[

clients/algoliasearch-client-python/algoliasearch/recommend/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import CallType, Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -10,7 +11,8 @@ class RecommendConfig(BaseConfig):
1011
def __init__(self, app_id: Optional[str], api_key: Optional[str]) -> None:
1112
super().__init__(app_id, api_key)
1213

13-
user_agent = UserAgent().add("Recommend")
14+
self._user_agent = UserAgent()
15+
self.add_user_agent("Recommend", __version__)
1416

1517
if app_id is None or not app_id:
1618
raise ValueError("`app_id` is missing.")
@@ -21,7 +23,7 @@ def __init__(self, app_id: Optional[str], api_key: Optional[str]) -> None:
2123
self.headers = {
2224
"x-algolia-application-id": app_id,
2325
"x-algolia-api-key": api_key,
24-
"user-agent": user_agent.get(),
26+
"user-agent": self._user_agent.get(),
2527
"content-type": "application/json",
2628
}
2729

0 commit comments

Comments
 (0)