Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Dict, Optional

from algoliasearch.http.hosts import HostsCollection
from algoliasearch.http.user_agent import UserAgent


class BaseConfig:
Expand All @@ -27,6 +28,8 @@ def __init__(self, app_id: Optional[str] = None, api_key: Optional[str] = None):
self.proxies: Optional[Dict[str, str]] = None
self.hosts: Optional[HostsCollection] = None

self.user_agent: UserAgent = UserAgent()

def set_client_api_key(self, api_key: str) -> None:
"""Sets a new API key to authenticate requests."""
self.api_key = api_key
Expand Down
3 changes: 3 additions & 0 deletions playground/python/app/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def main():
client = SearchClientSync(
environ.get("ALGOLIA_APPLICATION_ID"), environ.get("ALGOLIA_ADMIN_KEY")
)
client._config.user_agent.add("playground")

print("user_agent", client._config.user_agent.get())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this adds

user_agent Algolia for Python (4.9.2); Python (3.11.6); Search (4.9.2); playground (4.9.2)

print("client initialized", client)

try:
Expand Down
4 changes: 2 additions & 2 deletions playground/python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions templates/python/config.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class {{#lambda.pascalcase}}{{client}}{{/lambda.pascalcase}}Config(BaseConfig):
def __init__(self, app_id: Optional[str], api_key: Optional[str]{{#hasRegionalHost}}, region: {{#fallbackToAliasHost}}Optional[str] = None{{/fallbackToAliasHost}}{{^fallbackToAliasHost}}str = ""{{/fallbackToAliasHost}}{{/hasRegionalHost}}) -> None:
super().__init__(app_id, api_key)

user_agent = UserAgent().add("{{#lambda.pascalcase}}{{client}}{{/lambda.pascalcase}}")
self.user_agent = UserAgent().add("{{#lambda.pascalcase}}{{client}}{{/lambda.pascalcase}}")

if app_id is None or not app_id:
raise ValueError("`app_id` is missing.")
Expand All @@ -25,7 +25,7 @@ class {{#lambda.pascalcase}}{{client}}{{/lambda.pascalcase}}Config(BaseConfig):
self.headers = {
"x-algolia-application-id": app_id,
"x-algolia-api-key": api_key,
"user-agent": user_agent.get(),
"user-agent": self.user_agent.get(),
"content-type": "application/json",
}

Expand Down
Loading