# encode/httpx architecture

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

- Interactive diagram: https://gitdiagram.com/encode/httpx
- Repository: https://github.com/encode/httpx

## Overview

##### Main Components

a. Core Components:
- HTTP Client Layer (sync and async)
- Transport Layer
- Authentication System
- Content Handling
- URL Parsing & Management
- Exception Handling

b. Transport Implementations:
- HTTP/1.1 Transport
- HTTP/2 Transport
- WSGI Transport
- ASGI Transport
- Mock Transport (for testing)

**Top Layer: Public API**

**Middle Layer: Client Implementation**

**Bottom Layer: Transport Layer**

##### Component Relationships

a. Client Layer Components:
- How _client.py interfaces with _auth.py, _models.py, and _config.py
- Connection between sync and async clients
- Content handling (_content.py, _multipart.py) with the client layer

b. Transport Layer:
- How different transport implementations (_transports/) connect to the base transport
- Relationship between HTTP/1.1 and HTTP/2 transports
- WSGI and ASGI transport options

##### Important Elements to Highlight

a. Core Features:
- HTTP/1.1 and HTTP/2 support
- Sync/Async dual interface
- Authentication mechanisms
- Content encoding/decoding
- Cookie handling
- Session management

b. External Dependencies:
- httpcore
- h11/h2
- certifi
- idna
- sniffio

##### Data Flow Indicators

- Request flow from client through transport layers
- Response handling back through the layers
- Authentication flow
- Content encoding/decoding flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Public_API
        API["Public API"]:::api
        CLI["CLI Interface"]:::api
    end

    subgraph Client_Layer
        Client["HTTP Client"]:::client
        Auth["Authentication"]:::auth
        Models["Models"]:::core
        Config["Configuration"]:::core
        Content["Content Handling"]:::core
        Multipart["Multipart"]:::core
        Decoders["Decoders"]:::core
        URLs["URL Management"]:::core
        Exceptions["Exceptions"]:::core
        Types["Type Definitions"]:::core
        Utils["Utilities"]:::core
        Status["Status Codes"]:::core
    end

    subgraph Transport_Layer
        BaseTransport["Base Transport"]:::transport
        DefaultTransport["Default Transport"]:::transport
        WSGITransport["WSGI Transport"]:::transport
        ASGITransport["ASGI Transport"]:::transport
        MockTransport["Mock Transport"]:::transport
    end

    %% External Dependencies
    ExternalDeps["External Dependencies<br/>(httpcore, h11/h2, certifi,<br/>idna, sniffio)"]:::external

    %% Relationships
    API --> Client
    CLI --> Client
    Client --> Auth
    Client --> Models
    Client --> Config
    Client --> Content
    Client --> URLs
    Client --> Exceptions
    Content --> Multipart
    Content --> Decoders
    Client --> BaseTransport
    BaseTransport --> DefaultTransport
    BaseTransport --> WSGITransport
    BaseTransport --> ASGITransport
    BaseTransport --> MockTransport
    BaseTransport --> ExternalDeps

    %% Click Events
    click Client "https://github.com/encode/httpx/blob/master/httpx/_client.py"
    click API "https://github.com/encode/httpx/blob/master/httpx/_api.py"
    click Auth "https://github.com/encode/httpx/blob/master/httpx/_auth.py"
    click Models "https://github.com/encode/httpx/blob/master/httpx/_models.py"
    click Config "https://github.com/encode/httpx/blob/master/httpx/_config.py"
    click Content "https://github.com/encode/httpx/blob/master/httpx/_content.py"
    click Multipart "https://github.com/encode/httpx/blob/master/httpx/_multipart.py"
    click Decoders "https://github.com/encode/httpx/blob/master/httpx/_decoders.py"
    click URLs "https://github.com/encode/httpx/blob/master/httpx/_urls.py"
    click Exceptions "https://github.com/encode/httpx/blob/master/httpx/_exceptions.py"
    click Types "https://github.com/encode/httpx/blob/master/httpx/_types.py"
    click Utils "https://github.com/encode/httpx/blob/master/httpx/_utils.py"
    click Status "https://github.com/encode/httpx/blob/master/httpx/_status_codes.py"
    click CLI "https://github.com/encode/httpx/blob/master/httpx/_main.py"
    click BaseTransport "https://github.com/encode/httpx/blob/master/httpx/_transports/base.py"
    click DefaultTransport "https://github.com/encode/httpx/blob/master/httpx/_transports/default.py"
    click WSGITransport "https://github.com/encode/httpx/blob/master/httpx/_transports/wsgi.py"
    click ASGITransport "https://github.com/encode/httpx/blob/master/httpx/_transports/asgi.py"
    click MockTransport "https://github.com/encode/httpx/blob/master/httpx/_transports/mock.py"

    %% Styles
    classDef api fill:#f9f,stroke:#333,stroke-width:2px
    classDef client fill:#bbf,stroke:#333,stroke-width:2px
    classDef auth fill:#fbb,stroke:#333,stroke-width:2px
    classDef core fill:#ddd,stroke:#333,stroke-width:2px
    classDef transport fill:#bfb,stroke:#333,stroke-width:2px
    classDef external fill:#ffb,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["API Components"]:::api
        L2["Client Layer"]:::client
        L3["Authentication"]:::auth
        L4["Core Components"]:::core
        L5["Transport Layer"]:::transport
        L6["External Dependencies"]:::external
    end
```
