nineth 0.0.4__py3-none-any.whl

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.
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.4
2
+ Name: nineth
3
+ Version: 0.0.4
4
+ Summary: model sdk built by the 9th ditrict at tooig
5
+ Project-URL: Homepage, https://github.com/districtt/rooster
6
+ Project-URL: Bug Tracker, https://github.com/districtt/rooster/issues
7
+ Author-email: "Tooig, Inc" <tooighq@gmail.com>, Oyebamijo <boy@oyebamijo.com>
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.10
12
+ Requires-Dist: httpx<1.0,>=0.27.2
13
+ Description-Content-Type: text/markdown
14
+
15
+ # nineth-sdk
16
+
17
+ `nineth-sdk` is the lightweight Python SDK for the Rooster agent API.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pip install nineth
23
+ export NINETH_API_KEY="your-shared-api-key"
24
+ ```
25
+
26
+ ## 60-Second Start
27
+
28
+ ```python
29
+ from nineth import NinethClient
30
+
31
+ with NinethClient() as client:
32
+ result = client.invoke(
33
+ "Give me a tight market update on BTC.",
34
+ services=False,
35
+ cache=False,
36
+ )
37
+ print(result["final_response"])
38
+ ```
39
+
40
+ That works because:
41
+
42
+ - the SDK defaults to `https://weirdpablo--rooster-api.modal.run`
43
+ - the SDK reads `NINETH_API_KEY` automatically
44
+
45
+ ## Quick Start
46
+
47
+ ```python
48
+ import os
49
+ from nineth import NinethClient
50
+
51
+ client = NinethClient(api_key=os.environ["NINETH_API_KEY"])
52
+
53
+ response = client.invoke(
54
+ "Give me a terse overview of crude oil today.",
55
+ model_name="district/1984-m3-0317",
56
+ services=False,
57
+ cache=False,
58
+ )
59
+
60
+ print(response["final_response"])
61
+ client.close()
62
+ ```
63
+
64
+ ## Streaming
65
+
66
+ ```python
67
+ import os
68
+ from nineth import NinethClient
69
+
70
+ with NinethClient(api_key=os.environ["NINETH_API_KEY"]) as client:
71
+ for event in client.stream(
72
+ "Research Nvidia's latest earnings and summarize the key points.",
73
+ services=True,
74
+ service_names=["search_web", "read"],
75
+ cache=True,
76
+ max_iterations=6,
77
+ ):
78
+ print(event["type"], event["data"])
79
+ ```
80
+
81
+ ## Health Check
82
+
83
+ ```python
84
+ from nineth import NinethClient
85
+
86
+ with NinethClient() as client:
87
+ print(client.health())
88
+ ```
89
+
90
+ `health()` does not require authentication.
91
+
92
+ The SDK yields parsed SSE payloads as dictionaries. Typical event types are:
93
+
94
+ - `accepted`
95
+ - `run_started`
96
+ - `model_start`
97
+ - `model_delta`
98
+ - `model_response`
99
+ - `service_call`
100
+ - `service_response`
101
+ - `result`
102
+ - `completed`
103
+ - `error`
104
+
105
+ ## Async Client
106
+
107
+ ```python
108
+ import asyncio
109
+ import os
110
+ from nineth import AsyncNinethClient
111
+
112
+
113
+ async def main():
114
+ async with AsyncNinethClient(api_key=os.environ["NINETH_API_KEY"]) as client:
115
+ response = await client.invoke(
116
+ "Tell me whether gold is trending or ranging.",
117
+ services=False,
118
+ cache=False,
119
+ )
120
+ print(response["final_response"])
121
+
122
+
123
+ asyncio.run(main())
124
+ ```
125
+
126
+ ## Payload Options
127
+
128
+ The SDK maps directly to the API request body. The most important options are:
129
+
130
+ - `task_input`
131
+ - `model_name`
132
+ - `services`
133
+ - `service_names`
134
+ - `cache`
135
+ - `max_iterations`
136
+ - `reasoning_effort`
137
+ - `continuous`
138
+ - `images`
139
+ - `system_prompt`
140
+
141
+ Unknown request keys can be passed through with `extra={...}` in `build_payload(...)`.
142
+
143
+ ## What You Get Back
144
+
145
+ `invoke()` returns a dictionary like:
146
+
147
+ ```python
148
+ {
149
+ "process_id": "...",
150
+ "model_name": "district/1984-m3-0317",
151
+ "final_response": "...",
152
+ "usage": {...},
153
+ "thinking": [...],
154
+ "service_calls": [...],
155
+ "service_responses": [...],
156
+ "iterations": 2,
157
+ "events": [...],
158
+ }
159
+ ```
160
+
161
+ `stream()` yields one dictionary per SSE event, for example:
162
+
163
+ ```python
164
+ {
165
+ "type": "model_response",
166
+ "timestamp": "2026-04-03T00:00:00+00:00",
167
+ "process_id": "...",
168
+ "iteration": 1,
169
+ "data": {
170
+ "visible_response": "..."
171
+ }
172
+ }
173
+ ```
174
+
175
+ ## Authentication
176
+
177
+ Execution requests send the shared key in the `X-API-Key` header. The SDK reads it from:
178
+
179
+ - the `api_key=` constructor argument
180
+ - or the `NINETH_API_KEY` environment variable
181
+
182
+ `health()` does not require authentication, but `invoke()` and `stream()` do.
183
+
184
+ ## Overriding The Endpoint
185
+
186
+ Use a different deployment like this:
187
+
188
+ ```python
189
+ from nineth import NinethClient
190
+
191
+ client = NinethClient(
192
+ base_url="https://your-other-deployment.modal.run",
193
+ api_key="your-shared-api-key",
194
+ )
195
+ ```
@@ -0,0 +1,5 @@
1
+ roosted/__init__.py,sha256=GVhBHs49HB5By8DkQ5pNxvMD6JJ92IGdW5doTJc28EI,446
2
+ roosted/client.py,sha256=b00G_ImL54jLbFTTokSjYEdN-xUQCbb9schPq2aXlJI,8080
3
+ nineth-0.0.4.dist-info/METADATA,sha256=WTJqRuCv3qafTasxseeYocyL-thBDpFprIhny0j2OTg,3941
4
+ nineth-0.0.4.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
5
+ nineth-0.0.4.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
roosted/__init__.py ADDED
@@ -0,0 +1,18 @@
1
+ from .client import AsyncRoosterClient, RoosterAPIError, RoosterClient, build_payload
2
+
3
+ try:
4
+ from importlib.metadata import PackageNotFoundError, version
5
+ except ImportError:
6
+ from importlib_metadata import PackageNotFoundError, version
7
+
8
+ __all__ = [
9
+ "AsyncRoosterClient",
10
+ "RoosterAPIError",
11
+ "RoosterClient",
12
+ "build_payload",
13
+ ]
14
+
15
+ try:
16
+ __version__ = version("roosted")
17
+ except PackageNotFoundError:
18
+ __version__ = "0.0.0"
roosted/client.py ADDED
@@ -0,0 +1,239 @@
1
+ """Python client for the Rooster agent API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ from typing import Any, AsyncIterator, Dict, Iterator, Optional
8
+
9
+ import httpx
10
+
11
+
12
+ DEFAULT_TIMEOUT = 60.0
13
+ DEFAULT_BASE_URL = "https://weirdpablo--rooster-api.modal.run"
14
+ API_KEY_HEADER = "X-API-Key"
15
+
16
+
17
+ class RoosterAPIError(RuntimeError):
18
+ """Raised when the Rooster API returns an unexpected response."""
19
+
20
+
21
+ def build_payload(
22
+ task_input: str,
23
+ *,
24
+ model_name: Optional[str] = None,
25
+ services: bool = True,
26
+ service_names: Optional[list[str]] = None,
27
+ cache: bool = True,
28
+ max_iterations: int = 50,
29
+ reasoning_effort: str = "low",
30
+ process_id: Optional[str] = None,
31
+ user_id: Optional[str] = None,
32
+ debug: bool = False,
33
+ continuous: bool = False,
34
+ images: Optional[list[str]] = None,
35
+ system_prompt: Optional[str] = None,
36
+ extra: Optional[Dict[str, Any]] = None,
37
+ ) -> Dict[str, Any]:
38
+ payload: Dict[str, Any] = {
39
+ "task_input": task_input,
40
+ "model_name": model_name,
41
+ "services": services,
42
+ "service_names": service_names,
43
+ "cache": cache,
44
+ "max_iterations": max_iterations,
45
+ "reasoning_effort": reasoning_effort,
46
+ "process_id": process_id,
47
+ "user_id": user_id,
48
+ "debug": debug,
49
+ "continuous": continuous,
50
+ "images": images,
51
+ "system_prompt": system_prompt,
52
+ }
53
+ if extra:
54
+ payload.update(extra)
55
+ return {key: value for key, value in payload.items() if value is not None}
56
+
57
+
58
+ def _raise_for_status(response: httpx.Response) -> None:
59
+ try:
60
+ response.raise_for_status()
61
+ except httpx.HTTPStatusError as exc:
62
+ message = response.text.strip() or str(exc)
63
+ raise RoosterAPIError(message) from exc
64
+
65
+
66
+ def _parse_sse_lines(lines: Iterator[str]) -> Iterator[Dict[str, Any]]:
67
+ event_type = "message"
68
+ data_lines: list[str] = []
69
+
70
+ for raw_line in lines:
71
+ line = raw_line.rstrip("\r")
72
+ if not line:
73
+ if data_lines:
74
+ payload = json.loads("\n".join(data_lines))
75
+ payload.setdefault("type", event_type)
76
+ yield payload
77
+ event_type = "message"
78
+ data_lines = []
79
+ continue
80
+
81
+ if line.startswith(":"):
82
+ continue
83
+ if line.startswith("event:"):
84
+ event_type = line.split(":", 1)[1].strip()
85
+ continue
86
+ if line.startswith("data:"):
87
+ data_lines.append(line.split(":", 1)[1].strip())
88
+
89
+ if data_lines:
90
+ payload = json.loads("\n".join(data_lines))
91
+ payload.setdefault("type", event_type)
92
+ yield payload
93
+
94
+
95
+ class NinethClient:
96
+ """Synchronous client for the Nineth API."""
97
+
98
+ def __init__(
99
+ self,
100
+ base_url: Optional[str] = None,
101
+ api_key: Optional[str] = None,
102
+ *,
103
+ timeout: float = DEFAULT_TIMEOUT,
104
+ headers: Optional[Dict[str, str]] = None,
105
+ ):
106
+ resolved_base_url = (base_url or os.getenv("ROOSTER_BASE_URL") or DEFAULT_BASE_URL).rstrip("/")
107
+ if not resolved_base_url:
108
+ raise ValueError("A base_url or ROOSTER_BASE_URL environment variable is required.")
109
+
110
+ resolved_api_key = api_key or os.getenv("ROOSTER_API_KEY")
111
+ request_headers = dict(headers or {})
112
+ if resolved_api_key:
113
+ request_headers.setdefault(API_KEY_HEADER, resolved_api_key)
114
+
115
+ self.base_url = resolved_base_url
116
+ self.api_key = resolved_api_key
117
+ self._client = httpx.Client(
118
+ base_url=self.base_url,
119
+ timeout=timeout,
120
+ headers=request_headers or None,
121
+ )
122
+
123
+ def _ensure_api_key(self) -> None:
124
+ if not self.api_key and API_KEY_HEADER not in self._client.headers:
125
+ raise ValueError("An api_key or ROOSTER_API_KEY environment variable is required.")
126
+
127
+ def close(self) -> None:
128
+ self._client.close()
129
+
130
+ def __enter__(self) -> "NinethClient":
131
+ return self
132
+
133
+ def __exit__(self, exc_type, exc, tb) -> None:
134
+ self.close()
135
+
136
+ def health(self) -> Dict[str, Any]:
137
+ response = self._client.get("/health")
138
+ _raise_for_status(response)
139
+ return response.json()
140
+
141
+ def invoke(self, task_input: str, **kwargs: Any) -> Dict[str, Any]:
142
+ self._ensure_api_key()
143
+ payload = build_payload(task_input, **kwargs)
144
+ response = self._client.post("/agent", json=payload)
145
+ _raise_for_status(response)
146
+ return response.json()
147
+
148
+ def stream(self, task_input: str, **kwargs: Any) -> Iterator[Dict[str, Any]]:
149
+ self._ensure_api_key()
150
+ payload = build_payload(task_input, **kwargs)
151
+ with self._client.stream("POST", "/agent/stream", json=payload) as response:
152
+ _raise_for_status(response)
153
+ yield from _parse_sse_lines(response.iter_lines())
154
+
155
+
156
+ class AsyncNinethClient:
157
+ """Asynchronous client for the Nineth API."""
158
+
159
+ def __init__(
160
+ self,
161
+ base_url: Optional[str] = None,
162
+ api_key: Optional[str] = None,
163
+ *,
164
+ timeout: float = DEFAULT_TIMEOUT,
165
+ headers: Optional[Dict[str, str]] = None,
166
+ ):
167
+ resolved_base_url = (base_url or os.getenv("ROOSTER_BASE_URL") or DEFAULT_BASE_URL).rstrip("/")
168
+ if not resolved_base_url:
169
+ raise ValueError("A base_url or ROOSTER_BASE_URL environment variable is required.")
170
+
171
+ resolved_api_key = api_key or os.getenv("ROOSTER_API_KEY")
172
+ request_headers = dict(headers or {})
173
+ if resolved_api_key:
174
+ request_headers.setdefault(API_KEY_HEADER, resolved_api_key)
175
+
176
+ self.base_url = resolved_base_url
177
+ self.api_key = resolved_api_key
178
+ self._client = httpx.AsyncClient(
179
+ base_url=self.base_url,
180
+ timeout=timeout,
181
+ headers=request_headers or None,
182
+ )
183
+
184
+ def _ensure_api_key(self) -> None:
185
+ if not self.api_key and API_KEY_HEADER not in self._client.headers:
186
+ raise ValueError("An api_key or ROOSTER_API_KEY environment variable is required.")
187
+
188
+ async def aclose(self) -> None:
189
+ await self._client.aclose()
190
+
191
+ async def __aenter__(self) -> "AsyncNinethClient":
192
+ return self
193
+
194
+ async def __aexit__(self, exc_type, exc, tb) -> None:
195
+ await self.aclose()
196
+
197
+ async def health(self) -> Dict[str, Any]:
198
+ response = await self._client.get("/health")
199
+ _raise_for_status(response)
200
+ return response.json()
201
+
202
+ async def invoke(self, task_input: str, **kwargs: Any) -> Dict[str, Any]:
203
+ self._ensure_api_key()
204
+ payload = build_payload(task_input, **kwargs)
205
+ response = await self._client.post("/agent", json=payload)
206
+ _raise_for_status(response)
207
+ return response.json()
208
+
209
+ async def stream(self, task_input: str, **kwargs: Any) -> AsyncIterator[Dict[str, Any]]:
210
+ self._ensure_api_key()
211
+ payload = build_payload(task_input, **kwargs)
212
+ async with self._client.stream("POST", "/agent/stream", json=payload) as response:
213
+ _raise_for_status(response)
214
+ event_type = "message"
215
+ data_lines: list[str] = []
216
+
217
+ async for raw_line in response.aiter_lines():
218
+ line = raw_line.rstrip("\r")
219
+ if not line:
220
+ if data_lines:
221
+ payload = json.loads("\n".join(data_lines))
222
+ payload.setdefault("type", event_type)
223
+ yield payload
224
+ event_type = "message"
225
+ data_lines = []
226
+ continue
227
+
228
+ if line.startswith(":"):
229
+ continue
230
+ if line.startswith("event:"):
231
+ event_type = line.split(":", 1)[1].strip()
232
+ continue
233
+ if line.startswith("data:"):
234
+ data_lines.append(line.split(":", 1)[1].strip())
235
+
236
+ if data_lines:
237
+ payload = json.loads("\n".join(data_lines))
238
+ payload.setdefault("type", event_type)
239
+ yield payload