Skip to content

Commit ed4bd3e

Browse files
committed
fix: like set api key
1 parent 095a10e commit ed4bd3e

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

clients/algoliasearch-client-python/algoliasearch/http/base_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ def set_client_api_key(self, api_key: str) -> None:
3636
if self.headers is None:
3737
self.headers = {}
3838
self.headers["x-algolia-api-key"] = api_key
39+
40+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
41+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
42+
self.user_agent = self.user_agent.add(segment, version)
43+
44+
if self.headers is not None:
45+
self.headers["user-agent"] = self.user_agent.get()

playground/python/app/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def main():
1313
client = SearchClientSync(
1414
environ.get("ALGOLIA_APPLICATION_ID"), environ.get("ALGOLIA_ADMIN_KEY")
1515
)
16-
client._config.user_agent.add("playground")
16+
client.add_user_agent("playground")
1717

1818
print("user_agent", client._config.user_agent.get())
1919
print("client initialized", client)

templates/python/api.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ class {{classname}}{{#isSyncClient}}Sync{{/isSyncClient}}:
102102
"""Sets a new API key to authenticate requests."""
103103
self._transporter.config.set_client_api_key(api_key)
104104

105+
{{^isSyncClient}}async {{/isSyncClient}}def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
106+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
107+
self._transporter.config.add_user_agent(segment, version)
108+
105109
{{#isSearchClient}}
106110
{{> search_helpers}}
107111
{{/isSearchClient}}

0 commit comments

Comments
 (0)