---
source: https://iinventedlight.com/library/notes/python-expat.md
title: "Python xml.parsers.expat: fast XML parsing using Expat"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, xml.parsers.expat — Fast XML parsing using Expat; CPython, xml.parsers.expat documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-expat"
tags: [python, xml, expat, parser, markup]
client: Librarian
sources:
  - id: S1
    title: "xml.parsers.expat — Fast XML parsing using Expat"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/pyexpat.html
    accessed: 2026-11-24
    license: "PSF License Version 2"
  - id: S2
    title: "xml.parsers.expat documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/pyexpat.rst
    accessed: 2026-11-24
    license: "PSF License Version 2"
---
# Python xml.parsers.expat: fast XML parsing using Expat
**Answer:** xml.parsers.expat is a Python interface to Expat, a non-validating XML parser.

## What the module provides

It exposes a single xmlparser extension type that holds parser state.

Various attributes of the object can be set to handler functions.

Those handlers then run for character data and markup as a document is fed in.

Access to Expat goes through pyexpat, and calling pyexpat directly is deprecated.

## Errors, versions, and encodings

ExpatError is the exception raised when Expat reports an error.

ParserCreate returns a new xmlparser, and XMLParserType is that return type.

version_info is a tuple of three integers: major, minor and micro version.

Expat's repertoire of encodings can't be extended.

## See also

- [python-xml-etree](https://iinventedlight.com/library/notes/python-xml-etree/)
- [python-xml-sax](https://iinventedlight.com/library/notes/python-xml-sax/)
- [python-html-parser](https://iinventedlight.com/library/notes/python-html-parser/)

## Claims

- id: C1
  claim: xml.parsers.expat is a Python interface to the Expat non-validating XML parser.
  source: S1
  evidence: "The xml.parsers.expat module is a Python interface to the Expat non-validating XML parser."

- id: C2
  claim: ExpatError is raised when Expat reports an error.
  source: S1
  evidence: "The exception raised when Expat reports an error."

- id: C3
  claim: Direct use of the pyexpat module is deprecated.
  source: S1
  evidence: "Direct use of the pyexpat module is deprecated."

- id: C4
  claim: The module is an interface to the Expat non-validating XML parser.
  source: S2
  evidence: "An interface to the Expat non-validating XML parser."

## Sources

- [S1] xml.parsers.expat — Fast XML parsing using Expat. Python Software Foundation. https://docs.python.org/3/library/pyexpat.html . License: PSF License Version 2. Accessed 2026-11-24.

- [S2] xml.parsers.expat documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/pyexpat.rst . License: PSF License Version 2. Accessed 2026-11-24.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, xml.parsers.expat — Fast XML parsing using Expat; CPython, xml.parsers.expat documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
