# pallets/markupsafe architecture

> Architecture diagram of the GitHub repository pallets/markupsafe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pallets/markupsafe
- Repository: https://github.com/pallets/markupsafe

## Overview

MarkupSafe is a small Python library for turning text into HTML/XML-safe markup. A caller passes a value to the public API, which escapes ordinary text (or preserves objects implementing `__html__`) and returns a `Markup` string. `Markup` also provides string operations and formatting that escape inserted values, plus unescaping and tag stripping. Escaping uses the optional C accelerator when available and otherwise falls back to the native Python implementation; the excerpts show this selection, but do not establish further runtime components.

Main entry points: [`src/markupsafe/__init__.py`](https://github.com/pallets/markupsafe/blob/main/src/markupsafe/__init__.py) (Markup API), [`src/markupsafe/_speedups.c`](https://github.com/pallets/markupsafe/blob/main/src/markupsafe/_speedups.c) (C escaper), [`src/markupsafe/_native.py`](https://github.com/pallets/markupsafe/blob/main/src/markupsafe/_native.py) (Native escaper)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_caller(("Library caller"))
node_api["Markup API<br/>[__init__.py]"]
node_accelerator["C escaper<br/>[_speedups.c]"]
node_fallback["Native escaper<br/>[_native.py]"]

node_caller -->|"calls"| node_api
node_api -.->|"uses if available"| node_accelerator
node_api -->|"falls back to"| node_fallback

click node_api "https://github.com/pallets/markupsafe/blob/main/src/markupsafe/__init__.py"
click node_accelerator "https://github.com/pallets/markupsafe/blob/main/src/markupsafe/_speedups.c"
click node_fallback "https://github.com/pallets/markupsafe/blob/main/src/markupsafe/_native.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_caller toneIndigo
class node_api toneMint
class node_accelerator,node_fallback toneTeal
```

## Components

### Other components

- **Library caller**
- [Markup API](https://github.com/pallets/markupsafe/blob/main/src/markupsafe/__init__.py): `src/markupsafe/__init__.py`
- [C escaper](https://github.com/pallets/markupsafe/blob/main/src/markupsafe/_speedups.c): `src/markupsafe/_speedups.c`
- [Native escaper](https://github.com/pallets/markupsafe/blob/main/src/markupsafe/_native.py): `src/markupsafe/_native.py`

## Connections

- Library caller → Markup API: calls (evidence: `README.md`)
- Markup API → C escaper: uses if available (evidence: `src/markupsafe/__init__.py`)
- Markup API → Native escaper: falls back to (evidence: `src/markupsafe/__init__.py`)
