Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

tabapi

A scikit-learn-style Python client for tabular foundation models (TFMs) such as TabICL, served over HTTP.

TFMs predict by in-context learning: there is no training loop on your machine. tabapi sends your labelled rows to a TabAPI server, which runs the model, and gives you back predictions through the familiar fit / predict / predict_proba interface. You don't need torch or a GPU locally.

Status: alpha. The API may change between minor versions. You need access to a running TabAPI server.

Install

pip install tabapi

Requires Python 3.10+.

Quickstart

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from tabapi import TabAPIClassifier

X, y = load_breast_cancer(return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)

clf = TabAPIClassifier(base_url="https://your-tabapi-server.example.com")
clf.fit(X_train, y_train)          # local: checks and keeps the training data
y_pred = clf.predict(X_test)
proba = clf.predict_proba(X_test)
print(clf.score(X_test, y_test))

For a numeric target, TabAPIRegressor works the same way; predict returns floats (the mean of TabICL's predictive distribution):

from tabapi import TabAPIRegressor

reg = TabAPIRegressor(base_url="https://your-tabapi-server.example.com")
reg.fit(X_train, y_train)
y_pred = reg.predict(X_test)

Quantiles of TabICL's predictive distribution, e.g. for an 80% prediction interval, come from the same fitted regressor:

interval = reg.predict_quantiles(X_test, quantiles=[0.1, 0.9])  # shape (n, 2)
# or, as with local TabICL: reg.predict(X_test, output_type="quantiles", alphas=[0.1, 0.9])

Both are regular scikit-learn estimators, so they work with cross_val_score, Pipeline, clone, and so on.

The server is stateless. As with a local TabICL estimator, fit makes no network call: it keeps the training data, and each predict or predict_proba sends it along with the rows to predict. So a fitted estimator, and its pickle, contain the training data, and connection or authentication errors show up at the first predict.

Client 0.2 needs a 0.2 server; client 0.1.x works with server 0.1.x.

Authentication

If the server requires a bearer token, pass token=... or set the TABAPI_API_TOKEN environment variable. The environment variable is read at request time and is never stored on the estimator, so it does not end up in a pickled model.

Retries

Requests the server could not take (busy server, proxy with no healthy backend) are retried with exponential backoff, honouring Retry-After. So are requests whose connection dropped before a full answer (refused, reset, closed mid-response): the server stores nothing, so sending one again is harmless. Timeouts are not retried (see below). Tune this with max_retries and backoff_factor, or turn it off with max_retries=0.

Timings

After a predict, last_timings_ says where the time went, summed over the requests it took (one per batch):

clf.predict(X_test)
clf.last_timings_
# {'requests': 2, 'compute_seconds': 80.1, 'read_seconds': 0.2, 'queue_seconds': 0.4,
#  'fit_seconds': 61.2, 'predict_seconds': 18.9}

queue_seconds is time spent waiting for the server (other requests ahead), read_seconds the server reading the upload; the rest is computing. With a server before 0.3.0, only requests and compute_seconds are filled in.

Versions

The client sends its version with every request. If the server no longer supports it, the request fails with a 426 saying which version to install; if the server marks it deprecated, the client warns once (FutureWarning). Either way, pip install -U tabapi fixes it.

Timeouts

If a proxy gives up waiting for the server (504, or Cloudflare's 524 after 125 s) or the client's timeout runs out, predict raises tabapi.TabAPITimeoutError (a requests.HTTPError and a TimeoutError) without retrying: the same request would take as long again. The message gives the request's size. TabICL's predict time grows with the number of training rows, so use fewer training rows or predict fewer rows per call:

from tabapi import TabAPIClassifier, TabAPITimeoutError

try:
    clf.predict(X_test)
except TabAPITimeoutError as e:
    print(e)  # "... a request with 3200 training rows, 200 rows to predict ..."

Long requests and proxies. With a 0.3.0+ server, the client asks for keepalives: while the server works, it sends a space every few seconds, so a proxy in front of it never sees an idle connection and doesn't cut it (for example ingress-nginx after 60 s). timeout (300 s by default) then bounds the whole wait for an answer. With an older server it bounds each wait for data.

Request size limits

Every predict sends the training set, so servers cap the size of one request (the public ones: 2,500 training rows, 30,000 cells, 1,000 rows to predict). The client reads these limits from the server's /health and splits the rows to predict into batches that fit, sent one after another with the whole training set. You get one result, the same as from a single request. Set batch_size= to cap the batches lower, e.g. to keep each request short.

The training set can't be split: TabICL needs all of it in one pass. If it is over the limits, predict raises tabapi.TabAPILimitError (a requests.HTTPError and a ValueError) before uploading anything. Its limit, value and max attributes say which limit and by how much:

from tabapi import TabAPILimitError

try:
    clf.predict(X_test)
except TabAPILimitError as e:
    print(e.limit, e.value, e.max)  # max_train_rows 3200 2500

Use fewer training rows (e.g. a subsample) or fewer features. Servers older than 0.2.3 don't publish their limits: the client then learns them from the first 413 and batches the rest.

Upgrading from 0.1

0.2 is a breaking release, and needs a 0.2 server:

  • The server is stateless: fit no longer calls the server, and every predict sends the training data. There is no model_id any more.
  • target_name is gone: features and labels travel as separate files.
  • TabAPIClient is now private (tabapi._client). Use TabAPIClassifier or TabAPIRegressor, or call the HTTP API directly.
  • New: TabAPIRegressor.

Client 0.1.x keeps working with server 0.1.x.

License

BSD-3-Clause.

Metadata

Release files for tabapi 0.3.0rc2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tabapi 0.3.0rc2
File Size Uploaded Provenance Actions
tabapi-0.3.0rc2.tar.gz 38.0 kB Without provenance Details for tabapi-0.3.0rc2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tabapi 0.3.0rc2
File Interpreter ABI Platform Actions
tabapi-0.3.0rc2-py3-none-any.whl Python 3 none any Details for tabapi-0.3.0rc2-py3-none-any.whl

Total release size: 63.0 kB

Release files / tabapi-0.3.0rc2.tar.gz

Download URL tabapi-0.3.0rc2.tar.gz
Size 38.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a2f7f1316abfa699724645ab6cae1afbefa8d45dcf6a0e9fe4f7b57cc67c35bc
BLAKE2b-256 checksum
How to use checksums
89e77ea31e85f0e39f41a6c01bdec9d9e57dc931f4ea27e541beaf2314ea9f2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / tabapi-0.3.0rc2-py3-none-any.whl

Download URL tabapi-0.3.0rc2-py3-none-any.whl
Size 25.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3054c76d699af0ff1f0035924de3a59d98f02d81e8028323aff3b9f4faf32ab5
BLAKE2b-256 checksum
How to use checksums
863bec08d830cfb4e9035b76c43d5350950e0d24780066235f9e5b2f3642b8e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for tabapi 0.3.0rc2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page