sentiogate-python 1.3.0__tar.gz → 1.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sentiogate-python
3
- Version: 1.3.0
3
+ Version: 1.3.1
4
4
  Summary: Thin, zero-dependency Python client for SentioGate intelligent LLM router
5
5
  Author-email: SentioGate Team <dev@sentiogate.app>
6
6
  License-Expression: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sentiogate-python"
7
- version = "1.3.0"
7
+ version = "1.3.1"
8
8
  description = "Thin, zero-dependency Python client for SentioGate intelligent LLM router"
9
9
  authors = [{name = "SentioGate Team", email = "dev@sentiogate.app"}]
10
10
  readme = "README.md"
@@ -9,6 +9,7 @@ from .client import (
9
9
  AutoRouterClient,
10
10
  RouterClientError,
11
11
  parse_retry_after,
12
+ validate_base_url,
12
13
  )
13
14
 
14
15
  __version__ = VERSION
@@ -20,4 +21,5 @@ __all__ = [
20
21
  "AutoRouterClient",
21
22
  "RouterClientError",
22
23
  "parse_retry_after",
24
+ "validate_base_url",
23
25
  ]
@@ -18,7 +18,7 @@ import urllib.request
18
18
  from collections.abc import Callable, Iterator
19
19
  from typing import Any
20
20
 
21
- VERSION = "1.3.0"
21
+ VERSION = "1.3.1"
22
22
  # Sent on every request: honest, names this SDK, its real version and the OS it runs on (never a browser string,
23
23
  # never the default Python-urllib agent, which the gateway's bot check may refuse).
24
24
  USER_AGENT = f"sentiogate-python/{VERSION} ({platform.system() or 'unknown'})"
@@ -105,6 +105,17 @@ DEFAULT_BASE_URL = "https://api.sentiogate.dev"
105
105
  DEFAULT_TIMEOUT = 130.0
106
106
 
107
107
 
108
+ def validate_base_url(url: str | None) -> str:
109
+ """Validates and normalizes client base_url to ensure safe protocol scheme."""
110
+ target = (url or DEFAULT_BASE_URL).strip()
111
+ parsed = urllib.parse.urlsplit(target)
112
+ if parsed.scheme not in ("http", "https"):
113
+ raise ValueError(f"Invalid base_url scheme '{parsed.scheme}'. Only 'http' and 'https' are allowed.")
114
+ if not parsed.netloc:
115
+ raise ValueError(f"Invalid base_url '{target}': missing host.")
116
+ return target.rstrip("/")
117
+
118
+
108
119
  class AutoRouterClient:
109
120
  """Thin, zero-leak client SDK for connecting applications to SentioGate.
110
121
 
@@ -131,7 +142,7 @@ class AutoRouterClient:
131
142
  max_retry_wait: float = 60.0,
132
143
  user_agent: str | None = None,
133
144
  ) -> None:
134
- self.base_url = base_url.rstrip("/")
145
+ self.base_url = validate_base_url(base_url)
135
146
  self.api_key = api_key
136
147
  self.timeout = timeout
137
148
  self.max_retries = max(0, int(max_retries))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sentiogate-python
3
- Version: 1.3.0
3
+ Version: 1.3.1
4
4
  Summary: Thin, zero-dependency Python client for SentioGate intelligent LLM router
5
5
  Author-email: SentioGate Team <dev@sentiogate.app>
6
6
  License-Expression: Apache-2.0
@@ -31,6 +31,14 @@ class ClientTests(unittest.TestCase):
31
31
  def test_default_base_url(self):
32
32
  self.assertEqual(AutoRouterClient().base_url, "https://api.sentiogate.dev")
33
33
 
34
+ def test_validate_base_url_scheme(self):
35
+ with self.assertRaises(ValueError):
36
+ AutoRouterClient(base_url="file:///etc/passwd")
37
+ with self.assertRaises(ValueError):
38
+ AutoRouterClient(base_url="ftp://evil.com")
39
+ with self.assertRaises(ValueError):
40
+ AutoRouterClient(base_url="not-a-url")
41
+
34
42
  def test_internal_methods_removed(self):
35
43
  client = AutoRouterClient()
36
44
  for name in (