olbrain-python-sdk 0.5.0__tar.gz → 0.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {olbrain_python_sdk-0.5.0/olbrain_python_sdk.egg-info → olbrain_python_sdk-0.5.1}/PKG-INFO +1 -1
  2. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/AGENTS.md +4 -2
  3. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/__init__.py +1 -1
  4. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/client.py +6 -7
  5. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/olbrain.py +2 -1
  6. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1/olbrain_python_sdk.egg-info}/PKG-INFO +1 -1
  7. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/SOURCES.txt +1 -0
  8. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/setup.py +1 -1
  9. olbrain_python_sdk-0.5.1/tests/conftest.py +7 -0
  10. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/tests/test_client.py +9 -0
  11. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/tests/test_olbrain.py +5 -0
  12. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/.gitignore +0 -0
  13. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/LICENSE +0 -0
  14. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/MANIFEST.in +0 -0
  15. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/README.md +0 -0
  16. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/examples/advanced_features.py +0 -0
  17. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/examples/basic_usage.py +0 -0
  18. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/examples/error_handling.py +0 -0
  19. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/examples/session_management.py +0 -0
  20. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/examples/streaming_responses.py +0 -0
  21. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/exceptions.py +0 -0
  22. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/research.py +0 -0
  23. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/session.py +0 -0
  24. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/streaming.py +0 -0
  25. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/utils.py +0 -0
  26. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/dependency_links.txt +0 -0
  27. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/not-zip-safe +0 -0
  28. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/requires.txt +0 -0
  29. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/top_level.txt +0 -0
  30. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/pyproject.toml +0 -0
  31. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/requirements.txt +0 -0
  32. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/setup.cfg +0 -0
  33. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/tests/__init__.py +0 -0
  34. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/tests/test_exceptions.py +0 -0
  35. {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/tests/test_session.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: olbrain-python-sdk
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Official Python SDK for Olbrain AI agents
5
5
  Home-page: https://github.com/Olbrain/olbrain-sdk
6
6
  Author: Olbrain Team
@@ -56,7 +56,8 @@ with AgentClient(agent_id="your-agent-id", api_key=os.environ["OLBRAIN_API_KEY"]
56
56
  - `agent_id`: required. An empty value raises `ValueError`.
57
57
  - `api_key`: must start with `ak_`, `sk_live_`, `org_live_`, `sk_` or `org_`,
58
58
  or the constructor raises `ValueError`.
59
- - `agent_url`: optional. Defaults to `https://webhook.olbrain.com`.
59
+ - `agent_url`: optional. Defaults to the `OLBRAIN_AGENT_URL` environment
60
+ variable if set, otherwise `https://webhook.olbrain.com`.
60
61
 
61
62
  Chat calls are `POST {agent_url}/api/agents/webhook/{agent_id}` with
62
63
  `Authorization: Bearer <api_key>`. Session reads are
@@ -146,7 +147,8 @@ olbrain = Olbrain(api_key=os.environ["OLBRAIN_API_KEY"]) # server / sc
146
147
 
147
148
  `Olbrain(api_key=None, get_id_token=None, base_url=None, timeout=30)`:
148
149
  `api_key` must start `ak_`; `get_id_token` is a callable returning the
149
- token and is called before **every** request; `base_url` defaults to
150
+ token and is called before **every** request; `base_url` defaults to the
151
+ `OLBRAIN_AGENT_URL` environment variable if set, otherwise
150
152
  `https://webhook.olbrain.com`; `timeout` is in seconds. Give **exactly one** of
151
153
  `api_key` or `get_id_token`, or the constructor raises `ValidationError`.
152
154
 
@@ -39,7 +39,7 @@ from .exceptions import (
39
39
  BillingError,
40
40
  )
41
41
 
42
- __version__ = "0.5.0"
42
+ __version__ = "0.5.1"
43
43
  __author__ = "Olbrain Team"
44
44
  __email__ = "support@olbrain.com"
45
45
 
@@ -9,6 +9,7 @@ FIXES:
9
9
  - send_and_wait() now works correctly
10
10
  """
11
11
 
12
+ import os
12
13
  import requests
13
14
  import logging
14
15
  import time
@@ -150,7 +151,8 @@ class AgentClient:
150
151
  Args:
151
152
  agent_id: Agent identifier
152
153
  api_key: Access key (ak_…); 'sk_live_', 'org_live_', 'sk_' and 'org_' are also accepted
153
- agent_url: Optional agent URL (auto-constructed if not provided)
154
+ agent_url: Optional API base URL. Falls back to the OLBRAIN_AGENT_URL
155
+ environment variable, then https://webhook.olbrain.com
154
156
 
155
157
  Raises:
156
158
  ValueError: If agent_id or api_key is invalid
@@ -167,12 +169,9 @@ class AgentClient:
167
169
  self.agent_id = agent_id
168
170
  self.api_key = api_key
169
171
 
170
- # Auto-construct agent URL if not provided
171
- if agent_url:
172
- self.agent_url = agent_url.rstrip('/')
173
- else:
174
- # The Olbrain API. The old run.app host this SDK defaulted to no longer exists.
175
- self.agent_url = "https://webhook.olbrain.com"
172
+ # Explicit argument, then OLBRAIN_AGENT_URL, then the Olbrain API
173
+ agent_url = agent_url or os.environ.get("OLBRAIN_AGENT_URL") or "https://webhook.olbrain.com"
174
+ self.agent_url = agent_url.rstrip('/')
176
175
 
177
176
  self._streams = {} # session_id -> MessageStream
178
177
  self._running = False
@@ -5,6 +5,7 @@ Olbrain sign-in (get_id_token). The same API as the JavaScript SDK's `Olbrain`.
5
5
  """
6
6
 
7
7
  import json
8
+ import os
8
9
  from types import SimpleNamespace
9
10
  from typing import Any, Callable, Dict, Iterator, Optional
10
11
  from urllib.parse import urlencode
@@ -70,7 +71,7 @@ class Olbrain:
70
71
  raise ValidationError("api_key must be an Olbrain access key (ak_…)")
71
72
  self._api_key = api_key
72
73
  self._get_id_token = get_id_token
73
- self.base_url = (base_url or DEFAULT_BASE_URL).rstrip("/")
74
+ self.base_url = (base_url or os.environ.get("OLBRAIN_AGENT_URL") or DEFAULT_BASE_URL).rstrip("/")
74
75
  self.timeout = timeout
75
76
 
76
77
  def runs(agent_id):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: olbrain-python-sdk
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Official Python SDK for Olbrain AI agents
5
5
  Home-page: https://github.com/Olbrain/olbrain-sdk
6
6
  Author: Olbrain Team
@@ -26,6 +26,7 @@ olbrain_python_sdk.egg-info/not-zip-safe
26
26
  olbrain_python_sdk.egg-info/requires.txt
27
27
  olbrain_python_sdk.egg-info/top_level.txt
28
28
  tests/__init__.py
29
+ tests/conftest.py
29
30
  tests/test_client.py
30
31
  tests/test_exceptions.py
31
32
  tests/test_olbrain.py
@@ -15,7 +15,7 @@ if os.path.exists(readme_path):
15
15
  long_description = f.read()
16
16
 
17
17
  # Read version from the package
18
- version = "0.5.0"
18
+ version = "0.5.1"
19
19
 
20
20
  setup(
21
21
  name="olbrain-python-sdk",
@@ -0,0 +1,7 @@
1
+ import pytest
2
+
3
+
4
+ @pytest.fixture(autouse=True)
5
+ def no_url_from_env(monkeypatch):
6
+ # A developer's own OLBRAIN_AGENT_URL must not leak into tests
7
+ monkeypatch.delenv("OLBRAIN_AGENT_URL", raising=False)
@@ -26,6 +26,15 @@ class TestAgentClient:
26
26
  client = AgentClient(agent_id="a1", api_key="ak_test", agent_url="https://custom.example/")
27
27
  assert client.agent_url == "https://custom.example"
28
28
 
29
+ def test_env_url(self, monkeypatch):
30
+ monkeypatch.setenv("OLBRAIN_AGENT_URL", "http://localhost:8080/")
31
+ assert AgentClient(agent_id="a1", api_key="ak_test").agent_url == "http://localhost:8080"
32
+
33
+ def test_argument_beats_env_url(self, monkeypatch):
34
+ monkeypatch.setenv("OLBRAIN_AGENT_URL", "http://localhost:8080")
35
+ client = AgentClient(agent_id="a1", api_key="ak_test", agent_url="https://custom.example")
36
+ assert client.agent_url == "https://custom.example"
37
+
29
38
  def test_chat_goes_to_the_agent_webhook(self, client, requests_mock):
30
39
  requests_mock.post(CHAT, json={"session_id": "s1", "response": "Hi", "success": True})
31
40
  assert client.create_session(title="Hello") == "s1"
@@ -36,6 +36,11 @@ class TestConfig:
36
36
  with pytest.raises(ValidationError, match="ak_"):
37
37
  Olbrain(api_key="sk_live_x")
38
38
 
39
+ def test_env_url(self, monkeypatch):
40
+ monkeypatch.setenv("OLBRAIN_AGENT_URL", "http://localhost:8080/")
41
+ assert Olbrain(api_key="ak_test").base_url == "http://localhost:8080"
42
+ assert Olbrain(api_key="ak_test", base_url="https://custom.example").base_url == "https://custom.example"
43
+
39
44
  def test_asks_for_a_fresh_sign_in_token_on_every_call(self, requests_mock):
40
45
  tokens = iter(["t1", "t2"])
41
46
  olbrain = Olbrain(get_id_token=lambda: next(tokens))