infrarabbit 0.1.0__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,4 @@
1
+ """Client for the InfraRabbit price API. Data: InfraRabbit, infrarabbit.com."""
2
+ from .client import AsyncClient, Client, InfraRabbitError, __version__
3
+
4
+ __all__ = ["Client", "AsyncClient", "InfraRabbitError", "__version__"]
infrarabbit/client.py ADDED
@@ -0,0 +1,109 @@
1
+ """Stdlib-only client (urllib). AsyncClient runs the same calls in a worker thread."""
2
+ from __future__ import annotations
3
+
4
+ import asyncio
5
+ import json
6
+ import urllib.error
7
+ import urllib.parse
8
+ import urllib.request
9
+ from typing import Any, Dict, List, Optional
10
+
11
+ __version__ = "0.1.0"
12
+ BASE_URL = "https://infrarabbit.com"
13
+
14
+ JSON = Dict[str, Any]
15
+
16
+
17
+ class InfraRabbitError(Exception):
18
+ def __init__(self, status: int, message: str, url: str = ""):
19
+ super().__init__(f"HTTP {status} for {url}: {message}")
20
+ self.status = status
21
+ self.url = url
22
+
23
+
24
+ def _clean(params: Dict[str, Any]) -> Dict[str, str]:
25
+ out = {}
26
+ for k, v in params.items():
27
+ if v is None:
28
+ continue
29
+ out[k.rstrip("_")] = ("true" if v else "false") if isinstance(v, bool) else str(v)
30
+ return out
31
+
32
+
33
+ class Client:
34
+ """Sync client. Methods return the API's JSON as dicts."""
35
+
36
+ def __init__(self, base_url: str = BASE_URL, timeout: float = 30.0, user_agent: Optional[str] = None):
37
+ self.base_url = base_url.rstrip("/")
38
+ self.timeout = timeout
39
+ self.user_agent = user_agent or f"infrarabbit-python/{__version__}"
40
+
41
+ def _get(self, path: str, **params: Any) -> JSON:
42
+ q = urllib.parse.urlencode(_clean(params))
43
+ url = f"{self.base_url}{path}" + (f"?{q}" if q else "")
44
+ req = urllib.request.Request(url, headers={"User-Agent": self.user_agent, "Accept": "application/json"})
45
+ try:
46
+ with urllib.request.urlopen(req, timeout=self.timeout) as r:
47
+ return json.loads(r.read().decode("utf-8"))
48
+ except urllib.error.HTTPError as e:
49
+ raise InfraRabbitError(e.code, e.read().decode("utf-8", "replace")[:300], url) from None
50
+
51
+ def cheapest(self, category: str = "vps", *, vcpu: Optional[float] = None, ram_gb: Optional[float] = None,
52
+ disk_gb: Optional[float] = None, gpu: Optional[str] = None, gpu_count: Optional[int] = None,
53
+ region: Optional[str] = None, provider: Optional[str] = None, currency: str = "USD",
54
+ limit: int = 10, exact: bool = False) -> JSON:
55
+ """Cheapest current plans. Result: {"skus": [...], "cite": {...}, ...}."""
56
+ return self._get("/v1/cheapest", category=category, vcpu=vcpu, ram_gb=ram_gb, disk_gb=disk_gb, gpu=gpu,
57
+ gpu_count=gpu_count, region=region, provider=provider, currency=currency, limit=limit,
58
+ exact=exact or None)
59
+
60
+ def search_skus(self, q: Optional[str] = None, *, category: Optional[str] = None, provider: Optional[str] = None,
61
+ limit: int = 100, offset: int = 0) -> JSON:
62
+ return self._get("/v1/skus", q=q, category=category, provider=provider, limit=limit, offset=offset)
63
+
64
+ def sku(self, sku_id: str) -> JSON:
65
+ return self._get(f"/v1/skus/{urllib.parse.quote(sku_id, safe='/')}")
66
+
67
+ def history(self, sku_id: str, *, days: Optional[int] = None, from_: Optional[str] = None,
68
+ to: Optional[str] = None) -> JSON:
69
+ return self._get(f"/v1/skus/{urllib.parse.quote(sku_id, safe='/')}/history", days=days, from_=from_, to=to)
70
+
71
+ def changes(self, *, since: Optional[str] = None, category: Optional[str] = None, provider: Optional[str] = None,
72
+ kind: Optional[str] = None, sku_id: Optional[str] = None, limit: int = 200) -> JSON:
73
+ return self._get("/v1/changes", since=since, category=category, provider=provider, kind=kind,
74
+ sku_id=sku_id, limit=limit)
75
+
76
+ def since(self, date: str, *, kind: Optional[str] = None, provider: Optional[str] = None,
77
+ limit: Optional[int] = None) -> JSON:
78
+ """Grouped answer to 'what changed since <date>' (YYYY-MM-DD)."""
79
+ return self._get("/v1/since", date=date, kind=kind, provider=provider, limit=limit)
80
+
81
+ def vps_plans(self, *, ram: Optional[float] = None, vcpu: Optional[float] = None, region: Optional[str] = None,
82
+ limit: Optional[int] = None) -> JSON:
83
+ return self._get("/v1/vps/plans", ram=ram, vcpu=vcpu, region=region, limit=limit)
84
+
85
+ def index(self, series: Optional[str] = None, *, days: Optional[int] = None) -> JSON:
86
+ return self._get(f"/v1/index/{series}" if series else "/v1/index", days=days)
87
+
88
+ def providers(self, category: Optional[str] = None) -> JSON:
89
+ return self._get("/v1/providers", category=category)
90
+
91
+ def status(self) -> JSON:
92
+ return self._get("/v1/status")
93
+
94
+
95
+ class AsyncClient:
96
+ """Async twin of Client (same methods, awaitable)."""
97
+
98
+ def __init__(self, *args: Any, **kwargs: Any):
99
+ self._c = Client(*args, **kwargs)
100
+
101
+ def __getattr__(self, name: str) -> Any:
102
+ fn = getattr(self._c, name)
103
+ if name.startswith("_") or not callable(fn):
104
+ return fn
105
+
106
+ async def call(*a: Any, **kw: Any) -> JSON:
107
+ return await asyncio.to_thread(fn, *a, **kw)
108
+
109
+ return call
@@ -0,0 +1,33 @@
1
+ """LangChain tools. Install with: pip install "infrarabbit[langchain]"."""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ from typing import Optional
6
+
7
+ from langchain_core.tools import tool
8
+
9
+ from .client import Client
10
+
11
+ _client = Client(user_agent=None)
12
+
13
+
14
+ @tool
15
+ def infrarabbit_cheapest(category: str = "vps", vcpu: Optional[float] = None, ram_gb: Optional[float] = None,
16
+ region: Optional[str] = None, gpu: Optional[str] = None, limit: int = 5) -> str:
17
+ """Cheapest current list prices from InfraRabbit. category: vps, gpu, llm. Optional vcpu, ram_gb, region (e.g. eu), gpu (e.g. H100). Returns JSON with source and date per price."""
18
+ r = _client.cheapest(category, vcpu=vcpu, ram_gb=ram_gb, region=region, gpu=gpu, limit=limit)
19
+ keep = ("sku_id", "name", "provider", "price", "currency", "unit", "verified_at", "source_url")
20
+ return json.dumps({"skus": [{k: s.get(k) for k in keep} for s in r.get("skus", [])], "cite": r.get("cite"),
21
+ "attribution": "Data: InfraRabbit, infrarabbit.com"})
22
+
23
+
24
+ @tool
25
+ def infrarabbit_search(q: str, limit: int = 5) -> str:
26
+ """Search InfraRabbit SKUs (VPS plans, GPU instances, LLM models) by text, e.g. 'h100' or 'llama 3.3'."""
27
+ r = _client.search_skus(q, limit=limit)
28
+ keep = ("sku_id", "name", "provider", "price", "currency", "unit", "verified_at")
29
+ return json.dumps({"skus": [{k: s.get(k) for k in keep} for s in r.get("skus", [])],
30
+ "attribution": "Data: InfraRabbit, infrarabbit.com"})
31
+
32
+
33
+ tools = [infrarabbit_cheapest, infrarabbit_search]
infrarabbit/py.typed ADDED
File without changes
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.4
2
+ Name: infrarabbit
3
+ Version: 0.1.0
4
+ Summary: Python client for the InfraRabbit price API: cheapest VPS, GPU and LLM prices, with sources and dates.
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://infrarabbit.com
7
+ Project-URL: API, https://infrarabbit.com/api
8
+ Project-URL: Repository, https://github.com/InfraRabbit/sdk
9
+ Project-URL: Bug Tracker, https://github.com/InfraRabbit/sdk/issues
10
+ Keywords: infrarabbit,pricing,vps,gpu,llm,api-client
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Provides-Extra: langchain
17
+ Requires-Dist: langchain-core>=0.2; extra == "langchain"
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest; extra == "dev"
20
+ Requires-Dist: build; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # infrarabbit (Python)
24
+
25
+ Client for the public InfraRabbit price API: cheapest VPS, GPU and LLM prices, each with source and read date. No key.
26
+
27
+ ```python
28
+ # pip install infrarabbit
29
+ from infrarabbit import Client
30
+ c = Client()
31
+ top = c.cheapest("vps", ram_gb=4, region="eu", limit=1)["skus"][0]
32
+ print(top["name"], top["price"], top["currency"], top["verified_at"])
33
+ print(c.search_skus("h100", limit=3)["count"], "H100 SKUs") # also: sku(), history(), changes(), since(), vps_plans(), index()
34
+ ```
35
+
36
+ Async: `from infrarabbit import AsyncClient`, then `await AsyncClient().cheapest("gpu", gpu="H100")`.
37
+ LangChain: `pip install "infrarabbit[langchain]"`, then `from infrarabbit.langchain import tools`.
38
+ User-Agent is `infrarabbit-python/<version>`. MCP server: https://infrarabbit.com/mcp.
39
+
40
+ Data: InfraRabbit, infrarabbit.com. Data terms: https://infrarabbit.com/data (the MIT licence covers this code only).
@@ -0,0 +1,9 @@
1
+ infrarabbit/__init__.py,sha256=6tKfYF9MYqdqLbgCZTP7BcwR_JPlPT6vG902-OORRZ8,223
2
+ infrarabbit/client.py,sha256=9Jqbzo_QElnlthuKyrPeDe7CqNpXX8vvQEekG0IduwU,4921
3
+ infrarabbit/langchain.py,sha256=9liue8XoJt2UiNYxaW0YBUEkU4nTy4HXl6JhmKeDuUg,1571
4
+ infrarabbit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ infrarabbit-0.1.0.dist-info/licenses/LICENSE,sha256=I-NYLR-dzLtknupKNYtBhq69G2KhQdMsf_QLUipG0iQ,1068
6
+ infrarabbit-0.1.0.dist-info/METADATA,sha256=m9g3t4rPDrQaWAUcn8c5R5dk_lRMbl7NkbsT564yuxI,1728
7
+ infrarabbit-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ infrarabbit-0.1.0.dist-info/top_level.txt,sha256=BPb3XXSAdudhYLt2xvsSB6JHzKMuvGdPLVPJ0e0xIm8,12
9
+ infrarabbit-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 InfraRabbit
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 @@
1
+ infrarabbit