frutebox 0.0.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.
@@ -0,0 +1,4 @@
1
+ node_modules/
2
+ __pycache__/
3
+ dist/
4
+ *.egg-info/
frutebox-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Frutebox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,65 @@
1
+ Metadata-Version: 2.5
2
+ Name: frutebox
3
+ Version: 0.0.1
4
+ Summary: Official Frutebox SDK for Python — call the Frutebox network. No third-party AI SDK required.
5
+ Project-URL: Homepage, https://frutebox.com
6
+ Project-URL: Documentation, https://frutebox.com/docs
7
+ Project-URL: Changelog, https://frutebox.com/docs
8
+ Author: Frutebox
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai,assistant,frutebox,llm,sdk
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.8
21
+ Requires-Dist: requests>=2.25
22
+ Description-Content-Type: text/markdown
23
+
24
+ # frutebox
25
+
26
+ The official [Frutebox](https://frutebox.com) SDK for Python — call the Frutebox network with no
27
+ third-party AI library.
28
+
29
+ ```bash
30
+ pip install frutebox
31
+ ```
32
+
33
+ ```python
34
+ from frutebox import Frutebox
35
+
36
+ frutebox = Frutebox(api_key="sk_live_...") # or set FRUTEBOX_API_KEY
37
+ res = frutebox.chat.completions.create(
38
+ messages=[{"role": "user", "content": "Draft a friendly reminder email."}],
39
+ )
40
+ print(res["choices"][0]["message"]["content"])
41
+ ```
42
+
43
+ Supports chat + streaming, tool calling, images, videos, audio, moderations and models.
44
+ HTTPS is enforced, so your key is never sent in plaintext.
45
+
46
+ - Get an API key: <https://frutebox.com/app/keys>
47
+ - Documentation: <https://frutebox.com/docs>
48
+
49
+ `FRUTEBOX_API_KEY` is read from the environment when no `api_key` is passed. The older
50
+ `STEVAI_API_KEY` is still accepted so existing environments keep working; `FRUTEBOX_API_KEY` wins
51
+ when both are set.
52
+
53
+ ## Status
54
+
55
+ **0.0.1 is an early release.** The client is hand-written, and a fully typed client generated from
56
+ the published API specification is planned. The surface may change before 1.0.
57
+
58
+ This release calls the OpenAI-shaped compatibility endpoint (`/api/v1/chat/completions`), which is
59
+ being phased out in favour of the native Frutebox API. Your code here is not affected — the move
60
+ happens behind this client — but if you are calling the HTTP API directly, prefer the native
61
+ endpoint. See <https://frutebox.com/docs>.
62
+
63
+ ## Licence
64
+
65
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,42 @@
1
+ # frutebox
2
+
3
+ The official [Frutebox](https://frutebox.com) SDK for Python — call the Frutebox network with no
4
+ third-party AI library.
5
+
6
+ ```bash
7
+ pip install frutebox
8
+ ```
9
+
10
+ ```python
11
+ from frutebox import Frutebox
12
+
13
+ frutebox = Frutebox(api_key="sk_live_...") # or set FRUTEBOX_API_KEY
14
+ res = frutebox.chat.completions.create(
15
+ messages=[{"role": "user", "content": "Draft a friendly reminder email."}],
16
+ )
17
+ print(res["choices"][0]["message"]["content"])
18
+ ```
19
+
20
+ Supports chat + streaming, tool calling, images, videos, audio, moderations and models.
21
+ HTTPS is enforced, so your key is never sent in plaintext.
22
+
23
+ - Get an API key: <https://frutebox.com/app/keys>
24
+ - Documentation: <https://frutebox.com/docs>
25
+
26
+ `FRUTEBOX_API_KEY` is read from the environment when no `api_key` is passed. The older
27
+ `STEVAI_API_KEY` is still accepted so existing environments keep working; `FRUTEBOX_API_KEY` wins
28
+ when both are set.
29
+
30
+ ## Status
31
+
32
+ **0.0.1 is an early release.** The client is hand-written, and a fully typed client generated from
33
+ the published API specification is planned. The surface may change before 1.0.
34
+
35
+ This release calls the OpenAI-shaped compatibility endpoint (`/api/v1/chat/completions`), which is
36
+ being phased out in favour of the native Frutebox API. Your code here is not affected — the move
37
+ happens behind this client — but if you are calling the HTTP API directly, prefer the native
38
+ endpoint. See <https://frutebox.com/docs>.
39
+
40
+ ## Licence
41
+
42
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,35 @@
1
+ [project]
2
+ name = "frutebox"
3
+ version = "0.0.1"
4
+ description = "Official Frutebox SDK for Python — call the Frutebox network. No third-party AI SDK required."
5
+ readme = "README.md"
6
+ requires-python = ">=3.8"
7
+ license = { text = "MIT" }
8
+ authors = [{ name = "Frutebox" }]
9
+ keywords = ["frutebox", "ai", "llm", "assistant", "sdk"]
10
+ dependencies = ["requests>=2.25"]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Developers",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Operating System :: OS Independent",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Topic :: Software Development :: Libraries :: Python Modules",
19
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
20
+ ]
21
+
22
+ [project.urls]
23
+ Homepage = "https://frutebox.com"
24
+ Documentation = "https://frutebox.com/docs"
25
+ Changelog = "https://frutebox.com/docs"
26
+
27
+ [build-system]
28
+ requires = ["hatchling"]
29
+ build-backend = "hatchling.build"
30
+
31
+ [tool.hatch.build.targets.wheel]
32
+ packages = ["src/frutebox"]
33
+
34
+ [tool.hatch.build.targets.sdist]
35
+ include = ["src/frutebox", "README.md", "LICENSE", "pyproject.toml"]
@@ -0,0 +1,223 @@
1
+ """Official Frutebox SDK for Python.
2
+
3
+ A small, familiar client for the Frutebox network's API — no third-party AI SDK
4
+ required. Every answer comes from the real Frutebox network.
5
+
6
+ from frutebox import Frutebox
7
+
8
+ frutebox = Frutebox(api_key="sk_live_...")
9
+ res = frutebox.chat.completions.create(
10
+ messages=[{"role": "user", "content": "Draft a friendly reminder email."}],
11
+ )
12
+ print(res["choices"][0]["message"]["content"])
13
+ """
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import os
18
+ from typing import Any, Dict, Iterator, List, Optional
19
+
20
+ import requests
21
+
22
+ __all__ = ["Frutebox", "FruteboxError"]
23
+ __version__ = "0.0.1"
24
+
25
+
26
+ class FruteboxError(Exception):
27
+ def __init__(self, message: str, status: int = 0, code: Optional[str] = None):
28
+ super().__init__(message)
29
+ self.status = status
30
+ self.code = code
31
+
32
+
33
+ class Frutebox:
34
+ def __init__(self, api_key: Optional[str] = None, base_url: str = "https://frutebox.com", timeout: float = 60.0):
35
+ # ACCEPT BOTH, never drop the old one: this is a PUBLISHED SDK contract and the name is
36
+ # in users' own environments and CI. New spelling wins when both are set.
37
+ api_key = api_key or os.environ.get("FRUTEBOX_API_KEY") or os.environ.get("STEVAI_API_KEY")
38
+ if not api_key:
39
+ raise FruteboxError("A Frutebox API key is required.", 0, "missing_api_key")
40
+ base_url = base_url.rstrip("/")
41
+ # Enforce HTTPS so the key is never sent in plaintext (localhost exempt for dev).
42
+ is_local = base_url.startswith("http://localhost") or base_url.startswith("http://127.0.0.1")
43
+ if not base_url.startswith("https://") and not is_local:
44
+ raise FruteboxError("base_url must use https:// (refusing to send your key in plaintext).", 0, "insecure_base_url")
45
+ self._api_key = api_key
46
+ self.base_url = base_url
47
+ self._timeout = timeout
48
+ self.chat = _Chat(self)
49
+ self.images = _Images(self)
50
+ self.videos = _Videos(self)
51
+ self.audio = _Audio(self)
52
+ self.moderations = _Moderations(self)
53
+ self.models = _Models(self)
54
+
55
+ # --- transport -------------------------------------------------------
56
+ def _post(self, path: str, body: Dict[str, Any], stream: bool = False) -> requests.Response:
57
+ res = requests.post(
58
+ f"{self.base_url}{path}",
59
+ headers={"content-type": "application/json", "authorization": f"Bearer {self._api_key}"},
60
+ data=json.dumps(body),
61
+ stream=stream,
62
+ timeout=self._timeout,
63
+ )
64
+ if not res.ok:
65
+ raise self._error(res)
66
+ return res
67
+
68
+ @staticmethod
69
+ def _error(res: requests.Response) -> FruteboxError:
70
+ message = f"Frutebox request failed ({res.status_code})."
71
+ code = None
72
+ try:
73
+ body = res.json()
74
+ err = body.get("error")
75
+ if isinstance(err, str):
76
+ message = err
77
+ elif isinstance(err, dict):
78
+ message = err.get("message", message)
79
+ code = err.get("code")
80
+ except Exception:
81
+ pass
82
+ return FruteboxError(message, res.status_code, code)
83
+
84
+
85
+ class _Chat:
86
+ def __init__(self, client: "Frutebox"):
87
+ self.completions = _Completions(client)
88
+
89
+
90
+ class _Completions:
91
+ def __init__(self, client: "Frutebox"):
92
+ self._c = client
93
+
94
+ def create(
95
+ self,
96
+ messages: List[Dict[str, Any]],
97
+ model: Optional[str] = None,
98
+ stream: bool = False,
99
+ region: Optional[str] = None,
100
+ temperature: Optional[float] = None,
101
+ max_tokens: Optional[int] = None,
102
+ top_p: Optional[float] = None,
103
+ stop: Optional[Any] = None,
104
+ tools: Optional[List[Dict[str, Any]]] = None,
105
+ tool_choice: Optional[Any] = None,
106
+ response_format: Optional[Dict[str, Any]] = None,
107
+ seed: Optional[int] = None,
108
+ **extra: Any,
109
+ ) -> Any:
110
+ body: Dict[str, Any] = {"messages": messages, "stream": stream, **extra}
111
+ for key, val in (
112
+ ("model", model), ("region", region), ("temperature", temperature),
113
+ ("max_tokens", max_tokens), ("top_p", top_p), ("stop", stop),
114
+ ("tools", tools), ("tool_choice", tool_choice),
115
+ ("response_format", response_format), ("seed", seed),
116
+ ):
117
+ if val is not None:
118
+ body[key] = val
119
+ res = self._c._post("/api/v1/chat/completions", body, stream=stream)
120
+ if stream:
121
+ return self._iter(res)
122
+ return res.json()
123
+
124
+ @staticmethod
125
+ def _iter(res: requests.Response) -> Iterator[Dict[str, Any]]:
126
+ for line in res.iter_lines(decode_unicode=True):
127
+ if not line or not line.startswith("data:"):
128
+ continue
129
+ data = line[5:].strip()
130
+ if data == "[DONE]":
131
+ return
132
+ try:
133
+ yield json.loads(data)
134
+ except Exception:
135
+ continue
136
+
137
+
138
+ class _Images:
139
+ def __init__(self, client: "Frutebox"):
140
+ self._c = client
141
+
142
+ def generate(self, prompt: str, size: Optional[str] = None, region: Optional[str] = None) -> Dict[str, Any]:
143
+ body: Dict[str, Any] = {"prompt": prompt}
144
+ if size:
145
+ body["size"] = size
146
+ if region:
147
+ body["region"] = region
148
+ return self._c._post("/api/v1/images/generations", body).json()
149
+
150
+
151
+ class _Videos:
152
+ def __init__(self, client: "Frutebox"):
153
+ self._c = client
154
+
155
+ def generate(self, prompt: str, seconds: Optional[int] = None, region: Optional[str] = None) -> Dict[str, Any]:
156
+ body: Dict[str, Any] = {"prompt": prompt}
157
+ if seconds:
158
+ body["seconds"] = seconds
159
+ if region:
160
+ body["region"] = region
161
+ return self._c._post("/api/v1/videos/generations", body).json()
162
+
163
+
164
+ class _Audio:
165
+ def __init__(self, client: "Frutebox"):
166
+ self._c = client
167
+ self.transcriptions = _Transcriptions(client)
168
+
169
+ def speech(self, input: str, voice: Optional[str] = None, format: Optional[str] = None) -> Dict[str, Any]:
170
+ body: Dict[str, Any] = {"input": input}
171
+ if voice:
172
+ body["voice"] = voice
173
+ if format:
174
+ body["format"] = format
175
+ return self._c._post("/api/v1/audio/speech", body).json()
176
+
177
+
178
+ class _Transcriptions:
179
+ def __init__(self, client: "Frutebox"):
180
+ self._c = client
181
+
182
+ def create(self, file: Any, model: Optional[str] = None, language: Optional[str] = None) -> Dict[str, Any]:
183
+ data = {k: v for k, v in (("model", model), ("language", language)) if v is not None}
184
+ res = requests.post(
185
+ f"{self._c.base_url}/api/v1/audio/transcriptions",
186
+ headers={"authorization": f"Bearer {self._c._api_key}"},
187
+ files={"file": file},
188
+ data=data,
189
+ )
190
+ if not res.ok:
191
+ raise Frutebox._error(res)
192
+ return res.json()
193
+
194
+
195
+ class _Moderations:
196
+ def __init__(self, client: "Frutebox"):
197
+ self._c = client
198
+
199
+ def create(self, input: Any) -> Dict[str, Any]:
200
+ return self._c._post("/api/v1/moderations", {"input": input}).json()
201
+
202
+
203
+ class _Models:
204
+ def __init__(self, client: "Frutebox"):
205
+ self._c = client
206
+
207
+ def list(self) -> Dict[str, Any]:
208
+ res = requests.get(
209
+ f"{self._c.base_url}/api/v1/models",
210
+ headers={"authorization": f"Bearer {self._c._api_key}"},
211
+ )
212
+ if not res.ok:
213
+ raise Frutebox._error(res)
214
+ return res.json()
215
+
216
+ def retrieve(self, model_id: str) -> Dict[str, Any]:
217
+ res = requests.get(
218
+ f"{self._c.base_url}/api/v1/models/{model_id}",
219
+ headers={"authorization": f"Bearer {self._c._api_key}"},
220
+ )
221
+ if not res.ok:
222
+ raise Frutebox._error(res)
223
+ return res.json()