rftools-io 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.
rftools/__init__.py ADDED
@@ -0,0 +1,68 @@
1
+ # rftools/__init__.py
2
+ """
3
+ rftools — Python client for rftools.io (203 RF & electronics calculators).
4
+
5
+ Quick start (free tier, 5 calls/day):
6
+ import rftools
7
+ result = rftools.calculate("vswr-return-loss", {"vswr": 2.5})
8
+ print(result["returnLoss"]) # 9.54
9
+
10
+ Authenticated (API tier, 10,000 calls/month):
11
+ client = rftools.Client(api_key="rfc_live_xxx")
12
+ result = client.calculate("free-space-path-loss", {"frequency": 2400, "distance": 100})
13
+ """
14
+ import os
15
+
16
+ __version__ = "0.1.0"
17
+ __all__ = [
18
+ "Client",
19
+ "AsyncClient",
20
+ "calculate",
21
+ "list_calculators",
22
+ "get_calculator",
23
+ "CalculatorResult",
24
+ "CalculatorInfo",
25
+ "InputField",
26
+ "OutputField",
27
+ "RFToolsError",
28
+ "AuthError",
29
+ "RateLimitError",
30
+ "ValidationError",
31
+ "NotFoundError",
32
+ "APIError",
33
+ ]
34
+
35
+ from rftools.client import Client, AsyncClient
36
+ from rftools.types import CalculatorResult, CalculatorInfo, InputField, OutputField
37
+ from rftools.exceptions import (
38
+ RFToolsError, AuthError, RateLimitError, ValidationError, NotFoundError, APIError,
39
+ )
40
+
41
+ _default_client: Client | None = None
42
+
43
+
44
+ def _get_default_client() -> Client:
45
+ global _default_client
46
+ env_key = os.environ.get("RFTOOLS_API_KEY")
47
+ if _default_client is None or (env_key and _default_client._api_key != env_key):
48
+ _default_client = Client(api_key=env_key)
49
+ return _default_client
50
+
51
+
52
+ def calculate(slug: str, inputs: dict) -> CalculatorResult:
53
+ """
54
+ Run a calculator using the free tier (no API key required).
55
+
56
+ 5 calls/day per IP. For higher limits, use ``rftools.Client(api_key=...)``.
57
+ """
58
+ return _get_default_client().calculate(slug, inputs)
59
+
60
+
61
+ def list_calculators(category: str | None = None) -> list[CalculatorInfo]:
62
+ """Return metadata for all 203 calculators, optionally filtered by category."""
63
+ return _get_default_client().list_calculators(category=category)
64
+
65
+
66
+ def get_calculator(slug: str) -> CalculatorInfo:
67
+ """Return metadata for a single calculator by slug."""
68
+ return _get_default_client().get_calculator(slug)