# infermedica/python-api architecture

> Architecture diagram of the GitHub repository infermedica/python-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/infermedica/python-api
- Repository: https://github.com/infermedica/python-api

## Overview

##### Project type and purpose
- This is a Python client SDK (library) that wraps the Infermedica medical-diagnostic REST API (versions v2 & v3).
- It provides multiple “connectors” (Basic, Standard, Model) to communicate with the remote API endpoints, model request/response payloads, manage configuration, and expose exceptions.

##### File structure
- Top-level packaging:
- infermedica_api/ – main library
– connectors/ – versioned connector implementations (v2, v3) and common code
– webservice.py – HTTP client abstraction
– exceptions.py – SDK-specific exceptions
- examples/ – runnable scripts showing use of each API version
- setup.py, requirements.txt – packaging and dependencies
- Under connectors/v2 and connectors/v3:
- basic.py, standard.py, model.py (in v2) – three integration levels
- models/ (only in v2 Model connector) – classes representing API entities
- standard.py in v3 – high-level connector based on basic.py
- README details configuration, use cases, global vs. local connector registration, and exception types.

##### README for additional insights
- SDK supports two API versions (v2, v3).
- Three abstraction levels per version: Basic (raw HTTP), Standard (typed signatures), Model (domain-model objects).
- Configurable globally via infermedica_api.configure or locally by instantiating a connector.
- Error handling with custom exception classes.
- Examples folder maps 1:1 to connector methods.

##### Elements
- Blue for client application
- Green for SDK layers (connectors, webservice, models)
- Orange for external systems (REST API)
– Group related components (e.g., v2 connectors in one cluster, v3 connectors in another)

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef sdk fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px

    App["Client Application"]:::client
    App -->|"calls connector method"| Config

    Config["Configuration Manager"]:::sdk
    click Config "https://github.com/infermedica/python-api/blob/master/infermedica_api/__init__.py"

    subgraph "Connector Layer"
        subgraph "v2 Connectors"
            B2["BasicAPIv2Connector"]:::sdk
            click B2 "https://github.com/infermedica/python-api/blob/master/infermedica_api/connectors/v2/basic.py"
            S2["StandardAPIv2Connector"]:::sdk
            click S2 "https://github.com/infermedica/python-api/blob/master/infermedica_api/connectors/v2/standard.py"
            M2["ModelAPIv2Connector"]:::sdk
            click M2 "https://github.com/infermedica/python-api/blob/master/infermedica_api/connectors/v2/model.py"
        end
        subgraph "v3 Connectors"
            B3["BasicAPIv3Connector"]:::sdk
            click B3 "https://github.com/infermedica/python-api/blob/master/infermedica_api/connectors/v3/basic.py"
            S3["StandardAPIv3Connector"]:::sdk
            click S3 "https://github.com/infermedica/python-api/blob/master/infermedica_api/connectors/v3/standard.py"
        end
        Common["Common Connector Abstractions"]:::sdk
        click Common "https://github.com/infermedica/python-api/blob/master/infermedica_api/connectors/common.py"
    end

    Config -->|"provides config"| B2
    Config -->|"provides config"| S2
    Config -->|"provides config"| M2
    Config -->|"provides config"| B3
    Config -->|"provides config"| S3

    B2 -->|"uses common abstractions"| Common
    S2 -->|"uses common abstractions"| Common
    M2 -->|"uses common abstractions"| Common
    B3 -->|"uses common abstractions"| Common
    S3 -->|"uses common abstractions"| Common

    Common -->|"delegates HTTP call"| Webservice
    B2 -->|"delegates HTTP call"| Webservice
    S2 -->|"delegates HTTP call"| Webservice
    M2 -->|"delegates HTTP call"| Webservice
    B3 -->|"delegates HTTP call"| Webservice
    S3 -->|"delegates HTTP call"| Webservice

    Webservice["HTTP/Webservice Layer"]:::sdk
    click Webservice "https://github.com/infermedica/python-api/blob/master/infermedica_api/webservice.py"

    Webservice -->|"HTTP POST/GET"| APIv2
    Webservice -->|"HTTP POST/GET"| APIv3
    Webservice -->|"returns JSON"| Common

    APIv2["Infermedica REST API v2"]:::external
    APIv3["Infermedica REST API v3"]:::external

    Common -->|"returns raw dicts or models"| App

    M2 -->|"deserializes JSON to model classes"| Models
    Models["v2 Model Classes"]:::sdk
    click Models "https://github.com/infermedica/python-api/tree/master/infermedica_api/connectors/v2/models/"

    B2 -->|"on error raises"| Exceptions
    S2 -->|"on error raises"| Exceptions
    M2 -->|"on error raises"| Exceptions
    B3 -->|"on error raises"| Exceptions
    S3 -->|"on error raises"| Exceptions
    Webservice -->|"on error raises"| Exceptions

    Exceptions["Exception Module"]:::sdk
    click Exceptions "https://github.com/infermedica/python-api/blob/master/infermedica_api/exceptions.py"
    Exceptions -->|"propagates exceptions"| App

    Packaging["Packaging & Dependencies"]:::sdk
    click Packaging "https://github.com/infermedica/python-api/blob/master/setup.py"
    click Packaging "https://github.com/infermedica/python-api/blob/master/requirements.txt"

    Examples2["Example Scripts v2"]:::sdk
    click Examples2 "https://github.com/infermedica/python-api/tree/master/examples/v2/"
    Examples3["Example Scripts v3"]:::sdk
    click Examples3 "https://github.com/infermedica/python-api/tree/master/examples/v3/"

    App --> Packaging
    App --> Examples2
    App --> Examples3
```
