# priorlabs/tabpfn-client architecture

> Architecture diagram of the GitHub repository priorlabs/tabpfn-client, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/priorlabs/tabpfn-client
- Repository: https://github.com/priorlabs/tabpfn-client

## Overview

##### Project’s purpose and type
- Project Type: A Python API client library.
- Purpose: To offer an easy-to-use interface for interacting with the TabPFN cloud service for tabular data predictions. The README clearly shows that the target use case is providing tabular machine learning functionality (classifiers and regressors) as part of a cloud-based service.
- Important Points: Authentication via access tokens, API usage limits (cells, rate limiting), and a focus on ease-of-use with a scikit-learn-like interface.

##### File structure and underlying components
- browser_auth.py: Handles browser-based authentication workflow.
- client.py: Likely the core module that exposes high-level API functions.
- config.py & server_config.yaml: Manage local and server configuration settings.
- constants.py: Contains key constants used across various modules.
- estimator.py and mock_prediction.py: Provide functions for generating predictions and perhaps simulating responses.
- prompt_agent.py: May be responsible for constructing queries to the remote service.
- service_wrapper.py: Wraps the underlying API calls (e.g., HTTP requests).
- tabpfn_common_utils: A shared utility module.
- Testing directories (unit & integration) reveal how the team validates interactions – important for understanding boundaries and responsibilities.
- Build and quality tools are evident through configuration files (pyproject.toml, pre-commit, ruff settings) and GitHub workflows – while not core to runtime architecture, they indicate a modern, integrated development process.

A. Client Application (User Code)

B. TabPFN Client Library
- Sub-divide this into several internally interacting modules:
- Authentication Module: Represented by browser_auth.py and token management functions.
- Core Client Interface: Shown by client.py, which wraps API calls and exposes classifiers/regressors.
- Prediction & Estimation Logic: Illustrated via estimator.py and mock_prediction.py.
- Prompt & Service Wrapping: The prompt_agent.py and service_wrapper.py modules coordinate data preparation and API communication.
- Configuration: Configuration settings are managed through config.py and server_config.yaml.
- Common Utilities: Denote the shared routines in tabpfn_common_utils that support the overall functionality.

C. API and Remote TabPFN Server (External Component)
- Data Flow: The client sends data (training/test cells), receives predictions, and monitors API usage via HTTP headers.
- API Cost & Rate Limits: Highlight the calculation of API cost and the rate-limiting strategy.

##### Relationships and data flow
- The Authentication Module and the Core Client Interface (to supply access tokens).
- The Core Client and Service Wrapper modules, which then interface outward with the API Server.
- The Configuration Module that supplies settings to both the Client Interface and Service Wrapping components.
- A return path from the API Server back to the Service Wrapper and then to the Client, illustrating the handling of predictions and response headers (usage limits).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Nodes
    UA["User Application"]:::user

    subgraph "TabPFN Client Library"
        A1["Authentication (browser_auth)"]:::internal
        A2["Core Client (client.py)"]:::internal
        A3["Estimation (estimator.py)"]:::internal
        A4["Mock Prediction (mock_prediction.py)"]:::internal
        A5["Prompt Agent (prompt_agent.py)"]:::internal
        A6["Service Wrapper (service_wrapper.py)"]:::internal
        A7["Configuration (config.py)"]:::internal
        A8["Server Configuration (server_config.yaml)"]:::internal
        A9["Common Utilities"]:::internal
    end

    ES["TabPFN API Server"]:::external

    %% Relationships
    UA -->|"calls_API"| A2
    A1 -->|"supplies_token"| A2
    A7 -->|"configures"| A2
    A2 -->|"makes_request"| A6
    A5 -->|"prepares_prompt"| A6
    A6 -->|"API_call"| ES
    ES -->|"response_data"| A6
    A2 -->|"processes_prediction"| A3
    A2 -->|"simulate_response"| A4
    A8 -->|"loads_into"| A7
    A9 -->|"shared_utils"| A2

    %% Styles
    classDef internal fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef user fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;

    %% Click Events
    click A1 "https://github.com/priorlabs/tabpfn-client/blob/main/tabpfn_client/browser_auth.py"
    click A2 "https://github.com/priorlabs/tabpfn-client/blob/main/tabpfn_client/client.py"
    click A3 "https://github.com/priorlabs/tabpfn-client/blob/main/tabpfn_client/estimator.py"
    click A4 "https://github.com/priorlabs/tabpfn-client/blob/main/tabpfn_client/mock_prediction.py"
    click A5 "https://github.com/priorlabs/tabpfn-client/blob/main/tabpfn_client/prompt_agent.py"
    click A6 "https://github.com/priorlabs/tabpfn-client/blob/main/tabpfn_client/service_wrapper.py"
    click A7 "https://github.com/priorlabs/tabpfn-client/blob/main/tabpfn_client/config.py"
    click A8 "https://github.com/priorlabs/tabpfn-client/blob/main/tabpfn_client/server_config.yaml"
    click A9 "https://github.com/priorlabs/tabpfn-client/tree/main/tabpfn_client/tabpfn_common_utils"
```
