predictabl 0.1.0__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.
- predictabl-0.1.0/.github/workflows/ci.yml +21 -0
- predictabl-0.1.0/.github/workflows/publish.yml +24 -0
- predictabl-0.1.0/.gitignore +6 -0
- predictabl-0.1.0/CHANGELOG.md +16 -0
- predictabl-0.1.0/LICENSE +21 -0
- predictabl-0.1.0/PKG-INFO +160 -0
- predictabl-0.1.0/README.md +133 -0
- predictabl-0.1.0/pyproject.toml +58 -0
- predictabl-0.1.0/src/predictabl/__init__.py +105 -0
- predictabl-0.1.0/src/predictabl/__main__.py +52 -0
- predictabl-0.1.0/src/predictabl/_http.py +129 -0
- predictabl-0.1.0/src/predictabl/_progress.py +103 -0
- predictabl-0.1.0/src/predictabl/_version.py +1 -0
- predictabl-0.1.0/src/predictabl/assets/logo-128.png +0 -0
- predictabl-0.1.0/src/predictabl/client.py +831 -0
- predictabl-0.1.0/src/predictabl/errors.py +61 -0
- predictabl-0.1.0/src/predictabl/mcp.py +262 -0
- predictabl-0.1.0/tests/__init__.py +0 -0
- predictabl-0.1.0/tests/fake_api.py +226 -0
- predictabl-0.1.0/tests/test_client.py +348 -0
- predictabl-0.1.0/tests/test_integration.py +249 -0
- predictabl-0.1.0/tests/test_mcp.py +82 -0
- predictabl-0.1.0/uv.lock +1803 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
jobs:
|
|
7
|
+
test:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
strategy:
|
|
10
|
+
matrix:
|
|
11
|
+
python: ["3.10", "3.11", "3.12", "3.13"]
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: astral-sh/setup-uv@v6
|
|
15
|
+
with:
|
|
16
|
+
python-version: ${{ matrix.python }}
|
|
17
|
+
- run: uv sync
|
|
18
|
+
- run: uv run ruff check src tests
|
|
19
|
+
- run: uv run ruff format --check src tests
|
|
20
|
+
- run: uv run pytest -q
|
|
21
|
+
- run: uv build
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Publishes to PyPI when a GitHub release is published (tag vX.Y.Z).
|
|
2
|
+
# Uses PyPI trusted publishing: no API token is stored here. Configure it once
|
|
3
|
+
# on PyPI (project -> Publishing -> add GitHub publisher: this repo,
|
|
4
|
+
# workflow publish.yml, environment pypi).
|
|
5
|
+
name: Publish
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [published]
|
|
9
|
+
jobs:
|
|
10
|
+
publish:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment: pypi
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: astral-sh/setup-uv@v6
|
|
18
|
+
- run: uv sync && uv run pytest -q
|
|
19
|
+
- run: uv build
|
|
20
|
+
- name: Version matches the tag
|
|
21
|
+
run: |
|
|
22
|
+
v=$(python -c "import re;print(re.search(r'\"(.+)\"', open('src/predictabl/_version.py').read()).group(1))")
|
|
23
|
+
test "v$v" = "${GITHUB_REF_NAME}" || { echo "tag ${GITHUB_REF_NAME} != v$v"; exit 1; }
|
|
24
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First release.
|
|
6
|
+
|
|
7
|
+
- `upload()` files or a DataFrame; `Data.predict(question)` builds a tested
|
|
8
|
+
model in one call with step-by-step progress; `Data.plan()`,
|
|
9
|
+
`Plan.refine()`, `Plan.train()` to review first; `pb.plan()` to retrain an
|
|
10
|
+
existing plan.
|
|
11
|
+
- `Model.predict()` scores handed-in rows (batched) or the model's own data
|
|
12
|
+
(`ids`, `since`/`until`, `since_days`, `as_of`, `limit`, `filters`,
|
|
13
|
+
`include`). Predictions say what they mean and, for forecasts, the date
|
|
14
|
+
they are made from.
|
|
15
|
+
- Typed errors with the server's code and message.
|
|
16
|
+
- `predictabl mcp`: an MCP server for AI agents over the same client.
|
predictabl-0.1.0/LICENSE
ADDED
|
@@ -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.
|
|
@@ -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,133 @@
|
|
|
1
|
+
# Predictabl Python API library
|
|
2
|
+
|
|
3
|
+
Turn a question about your data into a trained, tested model, then score with
|
|
4
|
+
it. Predictabl reads your tables, plans the features in SQL you can review,
|
|
5
|
+
checks for leakage, trains and tests the model, and serves predictions.
|
|
6
|
+
|
|
7
|
+
**Documentation: [predictabl.tech/docs](https://predictabl.tech/docs/)** · for AI
|
|
8
|
+
agents, the whole documentation as one Markdown file:
|
|
9
|
+
[predictabl.tech/docs/llms-full.txt](https://predictabl.tech/docs/llms-full.txt)
|
|
10
|
+
|
|
11
|
+
> **Status: alpha (0.1).** Building models from code needs a *Build and
|
|
12
|
+
> score* token, which the hosted app starts offering with its next release.
|
|
13
|
+
> Scoring tokens work today.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install predictabl
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import predictabl as pb
|
|
21
|
+
|
|
22
|
+
pb.login("pk_...") # or set PREDICTABL_API_KEY
|
|
23
|
+
|
|
24
|
+
data = pb.upload("orders.csv")
|
|
25
|
+
model = data.predict("Will an order arrive late?")
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
✓ Uploading orders.csv · 18.2 MB
|
|
30
|
+
✓ Reading data 1 table
|
|
31
|
+
✓ Understanding Predict whether an order arrives after its promised date
|
|
32
|
+
✓ Planning 31 features · 2 excluded
|
|
33
|
+
✓ Building data
|
|
34
|
+
✓ Training lightgbm: kept 840 trees
|
|
35
|
+
✓ Final model auc 0.8712
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
model.report() # what it predicts, tested score, top features
|
|
40
|
+
model.predict(rows=new_orders) # score your own records (DataFrame or dicts)
|
|
41
|
+
model.url # the same model in the web app
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Everything you build from code also appears in the web app, labelled with the
|
|
45
|
+
token that created it.
|
|
46
|
+
|
|
47
|
+
## Get an API key
|
|
48
|
+
|
|
49
|
+
In the web app: **Settings → API access & usage → New token**.
|
|
50
|
+
|
|
51
|
+
- **Build and score** can upload data, plan and train models, and score them.
|
|
52
|
+
- **Score models only** can score your trained models and nothing else.
|
|
53
|
+
|
|
54
|
+
A token only ever reaches its owner's data and models. It cannot create other
|
|
55
|
+
tokens. Revoking it stops it immediately.
|
|
56
|
+
|
|
57
|
+
## Review the plan before training
|
|
58
|
+
|
|
59
|
+
`data.predict(question)` goes straight from question to model. To look first:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
plan = data.plan("Which customers will stop buying in the next 30 days?")
|
|
63
|
+
print(plan) # target, features, and what was excluded and why
|
|
64
|
+
plan = plan.refine("Don't use the support_tier column")
|
|
65
|
+
model = plan.train() # or plan.train(preset="fast_preview") for a 15-second check
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Scoring
|
|
69
|
+
|
|
70
|
+
How a model picks what to score depends on its kind (`model.kind`):
|
|
71
|
+
|
|
72
|
+
| kind | what `model.predict()` does | typical model |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| `flat` | needs `rows=`: one record in, one prediction out | survey, sensor reading, form |
|
|
75
|
+
| `event` | scores rows dated **today** in the data it trained on; pick a window with `since=`/`until=` or `since_days=` | orders, sign-ups, bookings |
|
|
76
|
+
| `forecast` | projects from the latest data, or `as_of="2026-10-01"` | sales per store, demand per item |
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
preds = model.predict(rows=df) # your records
|
|
80
|
+
preds = model.predict(since_days=7) # event model: last week's rows
|
|
81
|
+
preds = model.predict(ids=["store_12"], limit=48) # one entity
|
|
82
|
+
preds = model.predict(filters=[{"column": "city", "op": "eq", "value": "Milano"}],
|
|
83
|
+
include=["city"])
|
|
84
|
+
|
|
85
|
+
preds.meaning # e.g. "probability that customer churned"
|
|
86
|
+
preds.as_of # forecasts: the date they are made from
|
|
87
|
+
preds.note # e.g. why nothing matched, and the newest date in the data
|
|
88
|
+
preds.to_pandas()
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
A record you score can still contain its outcome column (e.g. a row copied from
|
|
92
|
+
the training file): it never reaches the model, and comes back as `actual` so
|
|
93
|
+
the call doubles as a check.
|
|
94
|
+
|
|
95
|
+
## Plans and limits
|
|
96
|
+
|
|
97
|
+
On Predictabl's AI key a free account has a fixed number of model builds (one
|
|
98
|
+
build = one question taken to a model; refining and retraining it is included).
|
|
99
|
+
With your own OpenAI or Anthropic key (Settings → AI provider) builds are not
|
|
100
|
+
limited. `pb.account()` shows what is left; running out raises
|
|
101
|
+
`predictabl.LimitReached` with what to do next.
|
|
102
|
+
|
|
103
|
+
## Use it from an AI agent (MCP)
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
claude mcp add predictabl --env PREDICTABL_API_KEY=pk_... -- uvx --from "predictabl[mcp]" predictabl mcp
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Then ask: *"Which of my customers are most likely to churn this month, and how
|
|
110
|
+
good is that model?"* The tools list your models, show how good they are, and
|
|
111
|
+
score them. They never upload or train.
|
|
112
|
+
|
|
113
|
+
## Configuration
|
|
114
|
+
|
|
115
|
+
| | |
|
|
116
|
+
|---|---|
|
|
117
|
+
| `PREDICTABL_API_KEY` | your token (`pk_...`) |
|
|
118
|
+
| `PREDICTABL_BASE_URL` | default `https://app.predictabl.tech/pub/v1`; a local instance is `http://localhost:8000/api/v1` |
|
|
119
|
+
|
|
120
|
+
For several accounts or instances, use clients directly:
|
|
121
|
+
`pb.Client(api_key=..., base_url=...)` has the same methods.
|
|
122
|
+
|
|
123
|
+
## Errors
|
|
124
|
+
|
|
125
|
+
All errors derive from `predictabl.PredictablError` and carry the server's
|
|
126
|
+
`code` and a message that says what to do: `AuthenticationError` (bad or
|
|
127
|
+
revoked key), `PermissionDenied` (the key's scope does not allow it),
|
|
128
|
+
`NotFound`, `LimitReached`, `InvalidRequest`, `BuildFailed` (with the server's
|
|
129
|
+
recovery `suggestions`).
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
MIT
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "predictabl"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Predictabl from Python: turn a question about your data into a trained model, then score it."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Predictabl" }]
|
|
14
|
+
keywords = ["machine learning", "prediction", "forecasting", "automl", "tabular", "mcp"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
23
|
+
]
|
|
24
|
+
dependencies = ["httpx>=0.27"]
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
pandas = ["pandas>=2.0"]
|
|
28
|
+
mcp = ["mcp>=1.2"]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://predictabl.tech"
|
|
32
|
+
Documentation = "https://github.com/predictabl/predictabl-python#readme"
|
|
33
|
+
Source = "https://github.com/predictabl/predictabl-python"
|
|
34
|
+
Issues = "https://github.com/predictabl/predictabl-python/issues"
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
predictabl = "predictabl.__main__:main"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.version]
|
|
40
|
+
path = "src/predictabl/_version.py"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["src/predictabl"]
|
|
44
|
+
|
|
45
|
+
[dependency-groups]
|
|
46
|
+
dev = ["pytest>=8", "pandas>=2.0", "mcp>=1.2", "ruff>=0.7"]
|
|
47
|
+
|
|
48
|
+
[tool.pytest.ini_options]
|
|
49
|
+
testpaths = ["tests"]
|
|
50
|
+
markers = ["integration: needs a running Predictabl backend (PREDICTABL_TEST_URL)"]
|
|
51
|
+
addopts = "-m 'not integration'"
|
|
52
|
+
|
|
53
|
+
[tool.ruff]
|
|
54
|
+
line-length = 90
|
|
55
|
+
target-version = "py310"
|
|
56
|
+
|
|
57
|
+
[tool.ruff.lint]
|
|
58
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Predictabl from Python.
|
|
2
|
+
|
|
3
|
+
import predictabl as pb
|
|
4
|
+
|
|
5
|
+
pb.login("pk_...") # or set PREDICTABL_API_KEY
|
|
6
|
+
data = pb.upload("orders.csv")
|
|
7
|
+
model = data.predict("Will an order arrive late?")
|
|
8
|
+
model.report()
|
|
9
|
+
model.predict(rows=new_orders)
|
|
10
|
+
|
|
11
|
+
Module-level functions use one shared client, configured by `login()` or the
|
|
12
|
+
PREDICTABL_API_KEY / PREDICTABL_BASE_URL environment variables. For several
|
|
13
|
+
accounts or instances at once, create `predictabl.Client` objects instead.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from ._progress import Update
|
|
19
|
+
from ._version import __version__
|
|
20
|
+
from .client import Client, Data, Model, Plan, Predictions
|
|
21
|
+
from .errors import (
|
|
22
|
+
ApiError,
|
|
23
|
+
AuthenticationError,
|
|
24
|
+
BuildFailed,
|
|
25
|
+
InvalidRequest,
|
|
26
|
+
LimitReached,
|
|
27
|
+
NotFound,
|
|
28
|
+
PermissionDenied,
|
|
29
|
+
PredictablError,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"__version__",
|
|
34
|
+
"login",
|
|
35
|
+
"client",
|
|
36
|
+
"account",
|
|
37
|
+
"upload",
|
|
38
|
+
"data",
|
|
39
|
+
"datasets",
|
|
40
|
+
"plan",
|
|
41
|
+
"model",
|
|
42
|
+
"models",
|
|
43
|
+
"Client",
|
|
44
|
+
"Data",
|
|
45
|
+
"Plan",
|
|
46
|
+
"Model",
|
|
47
|
+
"Predictions",
|
|
48
|
+
"Update",
|
|
49
|
+
"PredictablError",
|
|
50
|
+
"AuthenticationError",
|
|
51
|
+
"PermissionDenied",
|
|
52
|
+
"NotFound",
|
|
53
|
+
"LimitReached",
|
|
54
|
+
"InvalidRequest",
|
|
55
|
+
"BuildFailed",
|
|
56
|
+
"ApiError",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
_default: Client | None = None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def login(api_key: str | None = None, base_url: str | None = None, **kw) -> Client:
|
|
63
|
+
"""Configure the shared client. Without arguments, reads
|
|
64
|
+
PREDICTABL_API_KEY (and PREDICTABL_BASE_URL) from the environment."""
|
|
65
|
+
global _default
|
|
66
|
+
if _default is not None:
|
|
67
|
+
_default.close()
|
|
68
|
+
_default = Client(api_key=api_key, base_url=base_url, **kw)
|
|
69
|
+
return _default
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def client() -> Client:
|
|
73
|
+
"""The shared client, created from the environment on first use."""
|
|
74
|
+
global _default
|
|
75
|
+
if _default is None:
|
|
76
|
+
_default = Client()
|
|
77
|
+
return _default
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def account() -> dict:
|
|
81
|
+
return client().account()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def upload(source, name: str | None = None, **kw) -> Data:
|
|
85
|
+
return client().upload(source, name, **kw)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def data(data_id: str) -> Data:
|
|
89
|
+
return client().data(data_id)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def datasets() -> list[Data]:
|
|
93
|
+
return client().datasets()
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def plan(question_id: str) -> Plan:
|
|
97
|
+
return client().plan(question_id)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def model(model_id: str) -> Model:
|
|
101
|
+
return client().model(model_id)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def models(limit: int = 50) -> list[Model]:
|
|
105
|
+
return client().models(limit)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Command line: `predictabl whoami`, `predictabl models`, `predictabl mcp`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from . import errors
|
|
10
|
+
from ._version import __version__
|
|
11
|
+
from .client import Client
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def main(argv: list[str] | None = None) -> int:
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="predictabl", description="Predictabl from the shell."
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"--version", action="version", version=f"predictabl {__version__}"
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"--base-url", help="default: PREDICTABL_BASE_URL or the hosted app"
|
|
23
|
+
)
|
|
24
|
+
sub = parser.add_subparsers(dest="cmd", required=True)
|
|
25
|
+
sub.add_parser("whoami", help="your account, plan and builds left")
|
|
26
|
+
sub.add_parser("models", help="your models")
|
|
27
|
+
sub.add_parser(
|
|
28
|
+
"mcp", help="run the MCP server over stdio (for Claude and other agents)"
|
|
29
|
+
)
|
|
30
|
+
args = parser.parse_args(argv)
|
|
31
|
+
|
|
32
|
+
if args.cmd == "mcp":
|
|
33
|
+
from .mcp import serve
|
|
34
|
+
|
|
35
|
+
serve(base_url=args.base_url)
|
|
36
|
+
return 0
|
|
37
|
+
|
|
38
|
+
try:
|
|
39
|
+
with Client(base_url=args.base_url) as c:
|
|
40
|
+
if args.cmd == "whoami":
|
|
41
|
+
print(json.dumps(c.account(), indent=2))
|
|
42
|
+
elif args.cmd == "models":
|
|
43
|
+
for m in c.models():
|
|
44
|
+
print(f"{m.id} {m.state:<10} {m.title or ''}")
|
|
45
|
+
except errors.PredictablError as exc:
|
|
46
|
+
print(f"predictabl: {exc}", file=sys.stderr)
|
|
47
|
+
return 1
|
|
48
|
+
return 0
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
sys.exit(main())
|