predictabl 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.
- predictabl/__init__.py +105 -0
- predictabl/__main__.py +52 -0
- predictabl/_http.py +129 -0
- predictabl/_progress.py +103 -0
- predictabl/_version.py +1 -0
- predictabl/assets/logo-128.png +0 -0
- predictabl/client.py +831 -0
- predictabl/errors.py +61 -0
- predictabl/mcp.py +262 -0
- predictabl-0.1.0.dist-info/METADATA +160 -0
- predictabl-0.1.0.dist-info/RECORD +14 -0
- predictabl-0.1.0.dist-info/WHEEL +4 -0
- predictabl-0.1.0.dist-info/entry_points.txt +2 -0
- predictabl-0.1.0.dist-info/licenses/LICENSE +21 -0
predictabl/errors.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Errors raised by the Predictabl client.
|
|
2
|
+
|
|
3
|
+
Every error carries the server's machine `code` (when it sent one) and a
|
|
4
|
+
message meant for a person: the API phrases refusals as "what happened and
|
|
5
|
+
what to do", and these classes pass that through untouched.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PredictablError(Exception):
|
|
12
|
+
"""Base class for everything this package raises."""
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self, message: str, *, code: str | None = None, status: int | None = None
|
|
16
|
+
):
|
|
17
|
+
super().__init__(message)
|
|
18
|
+
self.message = message
|
|
19
|
+
self.code = code
|
|
20
|
+
self.status = status
|
|
21
|
+
|
|
22
|
+
def __str__(self) -> str:
|
|
23
|
+
return f"[{self.code}] {self.message}" if self.code else self.message
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AuthenticationError(PredictablError):
|
|
27
|
+
"""The API key is missing, wrong or revoked (HTTP 401)."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class PermissionDenied(PredictablError):
|
|
31
|
+
"""The API key is valid but its scope does not allow this (HTTP 403).
|
|
32
|
+
Scoring-only (`inference`) keys cannot upload, plan or train."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class NotFound(PredictablError):
|
|
36
|
+
"""No such object for this account (HTTP 404). Someone else's objects
|
|
37
|
+
look exactly like missing ones, by design."""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class LimitReached(PredictablError):
|
|
41
|
+
"""A free-plan allowance on Predictabl's AI key is used up (HTTP 402).
|
|
42
|
+
The message says how to continue (your own AI key, or an upgrade)."""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class InvalidRequest(PredictablError):
|
|
46
|
+
"""The request was understood but refused (HTTP 4xx), e.g. a model that
|
|
47
|
+
needs rows was asked to score without them."""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class BuildFailed(PredictablError):
|
|
51
|
+
"""A step of building a model (reading the data, finding the question,
|
|
52
|
+
planning, training) ended in failure. `suggestions` lists the server's
|
|
53
|
+
recovery options when it gave any."""
|
|
54
|
+
|
|
55
|
+
def __init__(self, message: str, *, code: str | None = None, suggestions=None):
|
|
56
|
+
super().__init__(message, code=code)
|
|
57
|
+
self.suggestions = list(suggestions or [])
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class ApiError(PredictablError):
|
|
61
|
+
"""Anything else the server answered with an error."""
|
predictabl/mcp.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""Predictabl as an MCP server, so an AI agent (Claude Code, Claude Desktop, any
|
|
2
|
+
MCP client) can discover your models and score with them.
|
|
3
|
+
|
|
4
|
+
claude mcp add predictabl --env PREDICTABL_API_KEY=pk_... -- \
|
|
5
|
+
uvx --from "predictabl[mcp]" predictabl mcp
|
|
6
|
+
|
|
7
|
+
It is a thin layer over the same client as the Python API: every tool is one
|
|
8
|
+
or two API calls, so what an agent sees is exactly what your code would get,
|
|
9
|
+
and a token reaches only its owner's models. The tools read and score; they
|
|
10
|
+
never upload or train.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import base64
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from .client import Client
|
|
19
|
+
|
|
20
|
+
INSTRUCTIONS = (
|
|
21
|
+
"Predictabl hosts this user's trained prediction models. Start with "
|
|
22
|
+
"list_models, check get_model before relying on a model, then use predict "
|
|
23
|
+
"for anything about what happens next. Quote `meaning` with numbers so the "
|
|
24
|
+
"user knows what a score is, and state `as_of` for forecasts."
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _icons():
|
|
29
|
+
try:
|
|
30
|
+
from mcp.types import Icon
|
|
31
|
+
|
|
32
|
+
raw = (Path(__file__).parent / "assets" / "logo-128.png").read_bytes()
|
|
33
|
+
uri = "data:image/png;base64," + base64.b64encode(raw).decode()
|
|
34
|
+
return [Icon(src=uri, mimeType="image/png", sizes=["128x128"])]
|
|
35
|
+
except Exception: # noqa: BLE001 - branding must never block startup
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _server_class():
|
|
40
|
+
"""mcp 2.x calls the high-level server MCPServer; 1.x called it FastMCP.
|
|
41
|
+
Same decorator API for what this module uses (tool(), run())."""
|
|
42
|
+
try:
|
|
43
|
+
from mcp.server.mcpserver import MCPServer
|
|
44
|
+
|
|
45
|
+
return MCPServer
|
|
46
|
+
except ImportError:
|
|
47
|
+
pass
|
|
48
|
+
try:
|
|
49
|
+
from mcp.server.fastmcp import FastMCP
|
|
50
|
+
|
|
51
|
+
return FastMCP
|
|
52
|
+
except ImportError as exc: # pragma: no cover - exercised by users only
|
|
53
|
+
raise SystemExit(
|
|
54
|
+
"The MCP server needs the `mcp` extra: pip install 'predictabl[mcp]'"
|
|
55
|
+
) from exc
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def build_server(client: Client):
|
|
59
|
+
"""The FastMCP server with every tool bound to `client`."""
|
|
60
|
+
Server = _server_class()
|
|
61
|
+
t = client._t
|
|
62
|
+
try:
|
|
63
|
+
mcp = Server("predictabl", instructions=INSTRUCTIONS, icons=_icons())
|
|
64
|
+
except TypeError: # an mcp release without server icons
|
|
65
|
+
mcp = Server("predictabl", instructions=INSTRUCTIONS)
|
|
66
|
+
|
|
67
|
+
@mcp.tool()
|
|
68
|
+
def list_models(limit: int = 50) -> list[dict]:
|
|
69
|
+
"""List trained models (successful training runs), newest first. Each
|
|
70
|
+
entry is one model you can inspect or score with; use its `id` with the
|
|
71
|
+
other tools. Returns: id, predicting (what it predicts), connection,
|
|
72
|
+
engine, headline metric (+ value), starred, started_at."""
|
|
73
|
+
out = []
|
|
74
|
+
for r in t.get("/runs", limit=max(limit * 2, 50)) or []:
|
|
75
|
+
if r.get("state") != "SUCCEEDED":
|
|
76
|
+
continue
|
|
77
|
+
hm = r.get("headline_metric") or {}
|
|
78
|
+
out.append(
|
|
79
|
+
{
|
|
80
|
+
"id": r["id"],
|
|
81
|
+
"predicting": r.get("opportunity_title"),
|
|
82
|
+
"connection": r.get("connection_name"),
|
|
83
|
+
"engine": r.get("engine_used") or r.get("engine_requested"),
|
|
84
|
+
"metric": hm.get("name"),
|
|
85
|
+
"metric_value": hm.get("value"),
|
|
86
|
+
"starred": bool(r.get("starred")),
|
|
87
|
+
"started_at": r.get("started_at"),
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
if len(out) >= limit:
|
|
91
|
+
break
|
|
92
|
+
return out
|
|
93
|
+
|
|
94
|
+
@mcp.tool()
|
|
95
|
+
def get_model(run_id: str) -> dict:
|
|
96
|
+
"""Detailed card for one model: what it predicts and what its number
|
|
97
|
+
MEANS, how it picks what to score (`kind`: forecast | event | flat),
|
|
98
|
+
the winning engine and its tested metric, rows trained/tested and the
|
|
99
|
+
top features. Check this before quoting a model's predictions."""
|
|
100
|
+
return client.model(run_id).report()
|
|
101
|
+
|
|
102
|
+
@mcp.tool()
|
|
103
|
+
def get_forecast(run_id: str, limit: int = 100) -> dict:
|
|
104
|
+
"""The forecasts this model produced AT TRAINING TIME: one prediction
|
|
105
|
+
per entity at the most recent training cutoff (a validated backtest
|
|
106
|
+
window, usually in the past). Returns as_of, total count and up to
|
|
107
|
+
`limit` items. For the genuine future ("next 7 days"), use `predict`."""
|
|
108
|
+
fc = t.get(f"/runs/{run_id}/forecasts")
|
|
109
|
+
if not fc:
|
|
110
|
+
raise RuntimeError(
|
|
111
|
+
f"no forecasts for run {run_id} (not a forecasting model?)"
|
|
112
|
+
)
|
|
113
|
+
items = (fc.get("items") or [])[:limit]
|
|
114
|
+
return {
|
|
115
|
+
"as_of": fc.get("score_at"),
|
|
116
|
+
"count": fc.get("count"),
|
|
117
|
+
"showing": len(items),
|
|
118
|
+
"items": items,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@mcp.tool()
|
|
122
|
+
def top_risks(run_id: str, n: int = 10, order: str = "desc") -> dict:
|
|
123
|
+
"""The N entities a CLASSIFIER scored highest (or lowest) on its
|
|
124
|
+
held-out test: "the top 10 customers at risk of churn". Each item has
|
|
125
|
+
`score` and `actual` (the held-out truth), so you can see whether the
|
|
126
|
+
top of the ranking was right. For forecasting models use
|
|
127
|
+
top_forecasts."""
|
|
128
|
+
return t.get(f"/runs/{run_id}/top-scored", top=n, order=order)
|
|
129
|
+
|
|
130
|
+
@mcp.tool()
|
|
131
|
+
def top_forecasts(run_id: str, n: int = 10, order: str = "desc") -> dict:
|
|
132
|
+
"""The top (or bottom) N entities by predicted value, ranked
|
|
133
|
+
server-side across the ENTIRE roster: exact "which store is highest".
|
|
134
|
+
`order`: "desc" (default) or "asc". Forecasting models only."""
|
|
135
|
+
fc = t.get(f"/runs/{run_id}/forecasts", top=n, order=order)
|
|
136
|
+
if not fc:
|
|
137
|
+
raise RuntimeError(
|
|
138
|
+
f"no forecasts to rank for run {run_id}: only per-step forecasting "
|
|
139
|
+
"models have them. For a classifier use top_risks."
|
|
140
|
+
)
|
|
141
|
+
return fc
|
|
142
|
+
|
|
143
|
+
@mcp.tool()
|
|
144
|
+
def get_backtest(run_id: str, entity: str | None = None) -> dict:
|
|
145
|
+
"""A forecasting model's held-out backtest for one entity: predicted vs
|
|
146
|
+
ACTUAL over the horizon, on data it did not train on. Omit `entity` for
|
|
147
|
+
the default one. Use it as evidence the model works."""
|
|
148
|
+
meta = t.get(f"/runs/{run_id}/forecast/meta")
|
|
149
|
+
if not meta:
|
|
150
|
+
raise RuntimeError(
|
|
151
|
+
f"no backtest panel for run {run_id} (not a per-step forecast?)"
|
|
152
|
+
)
|
|
153
|
+
ent = entity or meta.get("default_entity")
|
|
154
|
+
series = t.get(f"/runs/{run_id}/forecast", entity=ent) if ent else None
|
|
155
|
+
points = []
|
|
156
|
+
for p in (series or {}).get("points", []):
|
|
157
|
+
actual = (
|
|
158
|
+
p.get("actual_bt")
|
|
159
|
+
if p.get("actual_bt") is not None
|
|
160
|
+
else p.get("actual_hist")
|
|
161
|
+
)
|
|
162
|
+
if p.get("pred_bt") is None and actual is None:
|
|
163
|
+
continue
|
|
164
|
+
points.append(
|
|
165
|
+
{"date": p.get("date"), "actual": actual, "predicted": p.get("pred_bt")}
|
|
166
|
+
)
|
|
167
|
+
return {
|
|
168
|
+
"model": run_id,
|
|
169
|
+
"entity": ent,
|
|
170
|
+
"cadence": meta.get("cadence"),
|
|
171
|
+
"horizon": meta.get("horizon"),
|
|
172
|
+
"origin_date": (series or {}).get("origin_date"),
|
|
173
|
+
"points": points,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@mcp.tool()
|
|
177
|
+
def predict(
|
|
178
|
+
run_id: str,
|
|
179
|
+
since_days: int | None = None,
|
|
180
|
+
date_from: str | None = None,
|
|
181
|
+
date_to: str | None = None,
|
|
182
|
+
as_of: str | None = None,
|
|
183
|
+
filters: list[dict] | None = None,
|
|
184
|
+
include: list[str] | None = None,
|
|
185
|
+
top: int = 20,
|
|
186
|
+
entity_contains: str | None = None,
|
|
187
|
+
calibrated: bool = False,
|
|
188
|
+
) -> dict:
|
|
189
|
+
"""Score with a trained model ON FRESH DATA: features are rebuilt from
|
|
190
|
+
the data as of now, by the model itself. THE tool for "what happens
|
|
191
|
+
next".
|
|
192
|
+
|
|
193
|
+
- Forecast models: project from the latest data (or `as_of`,
|
|
194
|
+
YYYY-MM-DD). `entity_id` is `entity·cutoff·step`; step 1 is the
|
|
195
|
+
first future period. The response's `as_of` is the date forecast
|
|
196
|
+
FROM; say it, so stale data is visible.
|
|
197
|
+
- Event/risk models: score rows dated TODAY by default; widen with
|
|
198
|
+
`since_days`, or pick a window with `date_from`/`date_to`. If nothing
|
|
199
|
+
matched, the response has a `note` with the newest date in the data.
|
|
200
|
+
- Flat models (no time axis) cannot be scored this way: use
|
|
201
|
+
predict_rows with the records.
|
|
202
|
+
|
|
203
|
+
`filters`: [{"column","op","value"}], op eq|ne|in|contains|gt|gte|lt|lte,
|
|
204
|
+
on the model's table or a table it joins (e.g. city). `include`: extra
|
|
205
|
+
columns to return per prediction (in `context`). `entity_contains`:
|
|
206
|
+
only entities whose id contains this text. Results are ranked by value
|
|
207
|
+
and capped at `top`. Always read `meaning`: it says what the number is.
|
|
208
|
+
For MULTICLASS models read `predicted_class`, not `prediction`."""
|
|
209
|
+
body: dict = {"top": max(1, min(int(top), 2000)), "calibrated": calibrated}
|
|
210
|
+
if since_days is not None:
|
|
211
|
+
body["since_days"] = since_days
|
|
212
|
+
if date_from:
|
|
213
|
+
body["since"] = date_from
|
|
214
|
+
if date_to:
|
|
215
|
+
body["until"] = date_to
|
|
216
|
+
if as_of:
|
|
217
|
+
body["cutoff"] = as_of
|
|
218
|
+
if filters:
|
|
219
|
+
body["filters"] = filters
|
|
220
|
+
if include:
|
|
221
|
+
body["include"] = include
|
|
222
|
+
if entity_contains:
|
|
223
|
+
body["entity_contains"] = entity_contains
|
|
224
|
+
return t.post(f"/runs/{run_id}/predict", json=body)
|
|
225
|
+
|
|
226
|
+
@mcp.tool()
|
|
227
|
+
def predict_rows(run_id: str, rows: list[dict]) -> dict:
|
|
228
|
+
"""Score records you HAND IN: "would a machine with this torque and
|
|
229
|
+
temperature fail?". Each row is a dict keyed by the model's SOURCE
|
|
230
|
+
columns (the raw columns of its table), without the outcome. The
|
|
231
|
+
model's own feature SQL is applied, so there is no train/serve skew.
|
|
232
|
+
|
|
233
|
+
Best for flat models (one row in, one prediction). If the response has
|
|
234
|
+
a `warning`, the model summarises history and only your rows were
|
|
235
|
+
available: prefer `predict` for those. At most 1000 rows per call."""
|
|
236
|
+
return t.post(f"/runs/{run_id}/predict-records", json={"rows": rows[:1000]})
|
|
237
|
+
|
|
238
|
+
@mcp.tool()
|
|
239
|
+
def list_connections() -> list[dict]:
|
|
240
|
+
"""List the datasets (uploads and connected databases) on this account."""
|
|
241
|
+
return [
|
|
242
|
+
{
|
|
243
|
+
"id": c["id"],
|
|
244
|
+
"name": c.get("name"),
|
|
245
|
+
"kind": c.get("kind"),
|
|
246
|
+
"tables": c.get("table_count"),
|
|
247
|
+
}
|
|
248
|
+
for c in t.get("/connections") or []
|
|
249
|
+
]
|
|
250
|
+
|
|
251
|
+
@mcp.tool()
|
|
252
|
+
def account() -> dict:
|
|
253
|
+
"""The account behind this key: email, plan, builds used and left."""
|
|
254
|
+
return client.account()
|
|
255
|
+
|
|
256
|
+
return mcp
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def serve(base_url: str | None = None) -> None:
|
|
260
|
+
"""Run over stdio until the client disconnects."""
|
|
261
|
+
client = Client(base_url=base_url, client_tag="mcp")
|
|
262
|
+
build_server(client).run()
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: predictabl
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Predictabl from Python: turn a question about your data into a trained model, then score it.
|
|
5
|
+
Project-URL: Homepage, https://predictabl.tech
|
|
6
|
+
Project-URL: Documentation, https://github.com/predictabl/predictabl-python#readme
|
|
7
|
+
Project-URL: Source, https://github.com/predictabl/predictabl-python
|
|
8
|
+
Project-URL: Issues, https://github.com/predictabl/predictabl-python/issues
|
|
9
|
+
Author: Predictabl
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: automl,forecasting,machine learning,mcp,prediction,tabular
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: httpx>=0.27
|
|
22
|
+
Provides-Extra: mcp
|
|
23
|
+
Requires-Dist: mcp>=1.2; extra == 'mcp'
|
|
24
|
+
Provides-Extra: pandas
|
|
25
|
+
Requires-Dist: pandas>=2.0; extra == 'pandas'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# Predictabl Python API library
|
|
29
|
+
|
|
30
|
+
Turn a question about your data into a trained, tested model, then score with
|
|
31
|
+
it. Predictabl reads your tables, plans the features in SQL you can review,
|
|
32
|
+
checks for leakage, trains and tests the model, and serves predictions.
|
|
33
|
+
|
|
34
|
+
**Documentation: [predictabl.tech/docs](https://predictabl.tech/docs/)** · for AI
|
|
35
|
+
agents, the whole documentation as one Markdown file:
|
|
36
|
+
[predictabl.tech/docs/llms-full.txt](https://predictabl.tech/docs/llms-full.txt)
|
|
37
|
+
|
|
38
|
+
> **Status: alpha (0.1).** Building models from code needs a *Build and
|
|
39
|
+
> score* token, which the hosted app starts offering with its next release.
|
|
40
|
+
> Scoring tokens work today.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install predictabl
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import predictabl as pb
|
|
48
|
+
|
|
49
|
+
pb.login("pk_...") # or set PREDICTABL_API_KEY
|
|
50
|
+
|
|
51
|
+
data = pb.upload("orders.csv")
|
|
52
|
+
model = data.predict("Will an order arrive late?")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
✓ Uploading orders.csv · 18.2 MB
|
|
57
|
+
✓ Reading data 1 table
|
|
58
|
+
✓ Understanding Predict whether an order arrives after its promised date
|
|
59
|
+
✓ Planning 31 features · 2 excluded
|
|
60
|
+
✓ Building data
|
|
61
|
+
✓ Training lightgbm: kept 840 trees
|
|
62
|
+
✓ Final model auc 0.8712
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
model.report() # what it predicts, tested score, top features
|
|
67
|
+
model.predict(rows=new_orders) # score your own records (DataFrame or dicts)
|
|
68
|
+
model.url # the same model in the web app
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Everything you build from code also appears in the web app, labelled with the
|
|
72
|
+
token that created it.
|
|
73
|
+
|
|
74
|
+
## Get an API key
|
|
75
|
+
|
|
76
|
+
In the web app: **Settings → API access & usage → New token**.
|
|
77
|
+
|
|
78
|
+
- **Build and score** can upload data, plan and train models, and score them.
|
|
79
|
+
- **Score models only** can score your trained models and nothing else.
|
|
80
|
+
|
|
81
|
+
A token only ever reaches its owner's data and models. It cannot create other
|
|
82
|
+
tokens. Revoking it stops it immediately.
|
|
83
|
+
|
|
84
|
+
## Review the plan before training
|
|
85
|
+
|
|
86
|
+
`data.predict(question)` goes straight from question to model. To look first:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
plan = data.plan("Which customers will stop buying in the next 30 days?")
|
|
90
|
+
print(plan) # target, features, and what was excluded and why
|
|
91
|
+
plan = plan.refine("Don't use the support_tier column")
|
|
92
|
+
model = plan.train() # or plan.train(preset="fast_preview") for a 15-second check
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Scoring
|
|
96
|
+
|
|
97
|
+
How a model picks what to score depends on its kind (`model.kind`):
|
|
98
|
+
|
|
99
|
+
| kind | what `model.predict()` does | typical model |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| `flat` | needs `rows=`: one record in, one prediction out | survey, sensor reading, form |
|
|
102
|
+
| `event` | scores rows dated **today** in the data it trained on; pick a window with `since=`/`until=` or `since_days=` | orders, sign-ups, bookings |
|
|
103
|
+
| `forecast` | projects from the latest data, or `as_of="2026-10-01"` | sales per store, demand per item |
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
preds = model.predict(rows=df) # your records
|
|
107
|
+
preds = model.predict(since_days=7) # event model: last week's rows
|
|
108
|
+
preds = model.predict(ids=["store_12"], limit=48) # one entity
|
|
109
|
+
preds = model.predict(filters=[{"column": "city", "op": "eq", "value": "Milano"}],
|
|
110
|
+
include=["city"])
|
|
111
|
+
|
|
112
|
+
preds.meaning # e.g. "probability that customer churned"
|
|
113
|
+
preds.as_of # forecasts: the date they are made from
|
|
114
|
+
preds.note # e.g. why nothing matched, and the newest date in the data
|
|
115
|
+
preds.to_pandas()
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
A record you score can still contain its outcome column (e.g. a row copied from
|
|
119
|
+
the training file): it never reaches the model, and comes back as `actual` so
|
|
120
|
+
the call doubles as a check.
|
|
121
|
+
|
|
122
|
+
## Plans and limits
|
|
123
|
+
|
|
124
|
+
On Predictabl's AI key a free account has a fixed number of model builds (one
|
|
125
|
+
build = one question taken to a model; refining and retraining it is included).
|
|
126
|
+
With your own OpenAI or Anthropic key (Settings → AI provider) builds are not
|
|
127
|
+
limited. `pb.account()` shows what is left; running out raises
|
|
128
|
+
`predictabl.LimitReached` with what to do next.
|
|
129
|
+
|
|
130
|
+
## Use it from an AI agent (MCP)
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
claude mcp add predictabl --env PREDICTABL_API_KEY=pk_... -- uvx --from "predictabl[mcp]" predictabl mcp
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Then ask: *"Which of my customers are most likely to churn this month, and how
|
|
137
|
+
good is that model?"* The tools list your models, show how good they are, and
|
|
138
|
+
score them. They never upload or train.
|
|
139
|
+
|
|
140
|
+
## Configuration
|
|
141
|
+
|
|
142
|
+
| | |
|
|
143
|
+
|---|---|
|
|
144
|
+
| `PREDICTABL_API_KEY` | your token (`pk_...`) |
|
|
145
|
+
| `PREDICTABL_BASE_URL` | default `https://app.predictabl.tech/pub/v1`; a local instance is `http://localhost:8000/api/v1` |
|
|
146
|
+
|
|
147
|
+
For several accounts or instances, use clients directly:
|
|
148
|
+
`pb.Client(api_key=..., base_url=...)` has the same methods.
|
|
149
|
+
|
|
150
|
+
## Errors
|
|
151
|
+
|
|
152
|
+
All errors derive from `predictabl.PredictablError` and carry the server's
|
|
153
|
+
`code` and a message that says what to do: `AuthenticationError` (bad or
|
|
154
|
+
revoked key), `PermissionDenied` (the key's scope does not allow it),
|
|
155
|
+
`NotFound`, `LimitReached`, `InvalidRequest`, `BuildFailed` (with the server's
|
|
156
|
+
recovery `suggestions`).
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
predictabl/__init__.py,sha256=0KwF9vUdg9Q_8tRgkyJDHBLHYkKmTxr6FWVa0sPn5Lc,2375
|
|
2
|
+
predictabl/__main__.py,sha256=W1g9RAwxgzCz5ByVfENg7n9_xVFeuYSUDkWLLeHIGtA,1524
|
|
3
|
+
predictabl/_http.py,sha256=MYfNAc53Jc4N48-4zn_KU4uXKcdozY-tV-bgi5nk1Q8,4471
|
|
4
|
+
predictabl/_progress.py,sha256=zsf5PJ-nViCYf_4EOU2ZZVAAoEKkX4pGw7US3zOfSrU,3458
|
|
5
|
+
predictabl/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
6
|
+
predictabl/client.py,sha256=RDuGRJK_p2S1DHAw2DlqEcoIMgX4Jy9y356dIC4ge-Q,29705
|
|
7
|
+
predictabl/errors.py,sha256=Eus12DOTHZq-8NBmfNNVF-767TZRGBpF_0xYffxebKM,2036
|
|
8
|
+
predictabl/mcp.py,sha256=KMiiImJjdumu5rNKE89pMSAtZXVLgBBTOwxMNow9lVc,10792
|
|
9
|
+
predictabl/assets/logo-128.png,sha256=RXc2Zci9riDv6jz0zr4UnFIGoVYCbeSc3sztl_hHtQU,7771
|
|
10
|
+
predictabl-0.1.0.dist-info/METADATA,sha256=1x1uRhn2iJQsUgM6uVniy9ku5G4317TpyPACqUP-QxU,6111
|
|
11
|
+
predictabl-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
12
|
+
predictabl-0.1.0.dist-info/entry_points.txt,sha256=9QXysFU2nEkahX_xv1xnneLmUpsVao3dnhLHsifkWw8,56
|
|
13
|
+
predictabl-0.1.0.dist-info/licenses/LICENSE,sha256=EA5vRqAE-hKyxexJiBs-1jV8WWSfAVTFg3SMqgb2eK0,1067
|
|
14
|
+
predictabl-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Predictabl
|
|
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.
|