defusedxml

Drop-in replacements for Python's XML modules that block XML-bomb and entity-expansion attacks

Library
PyPI
v0.7.1
551stars
Custom / Unknown

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
41/100Fair
Development Activity0
Maintenance20
Community64
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture75
Code Quality82
Innovation65
Learning Curve92

defusedxml provides hardened drop-in replacements for Python’s standard-library XML parsing modules — xml.etree.ElementTree, xml.dom.minidom, xml.sax, xmlrpc, and lxml.etree — that disable or guard against the entity-expansion and external-entity vulnerabilities present in the defaults. Python’s built-in XML parsers are, by design, vulnerable to attacks like billion-laughs entity expansion, quadratic blowup, external entity (XXE) file disclosure, and DTD retrieval, none of which most application code is prepared to defend against.

Rather than requiring developers to hand-configure every parser’s security options correctly, defusedxml ships pre-configured, secure-by-default parser wrappers with the same API as the modules they replace, so switching a vulnerable import xml.etree.ElementTree as ET to import defusedxml.ElementTree as ET closes the relevant attack classes with a one-line change.

What You Get

  • defusedxml.ElementTree as a secure drop-in for xml.etree.ElementTree
  • defusedxml.minidom, defusedxml.sax, and defusedxml.pulldom secure equivalents of their stdlib counterparts
  • defusedxml.expatbuilder and defusedxml.expatreader for lower-level Expat-based parsing with entity protections
  • defusedxml.xmlrpc to monkey-patch Python’s xmlrpc client/server against XML attacks
  • defusedxml.lxml for adding the same protections when using the third-party lxml library
  • Clear, documented exceptions (EntitiesForbidden, ExternalReferenceForbidden, etc.) raised when an attack pattern is detected

Common Use Cases

  • Replacing unsafe stdlib XML parsing in any Python service that accepts XML from untrusted sources (uploads, APIs, SOAP)
  • Hardening SAML, RSS/Atom feed, or SOAP/XML-RPC processing pipelines against XXE and billion-laughs attacks
  • Passing security audits or compliance checks that flag raw xml.etree/xml.dom.minidom usage as a known vulnerability class
  • Safely parsing XML configuration or data files uploaded by end users in web applications

Under The Hood

Architecture The package is a set of thin, focused wrapper modules — common.py (85 lines) defines the shared DTDForbidden, EntitiesForbidden, and ExternalReferenceForbidden exception types plus the core _generate_etree_functions-style guarding logic, while each of ElementTree.py (188 lines), minidom.py, sax.py, pulldom.py, expatbuilder.py, expatreader.py, cElementTree.py, lxml.py, and xmlrpc.py reimplements just enough of its corresponding stdlib module’s public API to intercept parser construction and inject a secure Expat/lxml resolver that raises rather than expands dangerous constructs; __init__.py centralizes the package’s parse-and-raise convenience helpers. The design deliberately keeps each module’s surface area minimal and mirrors the stdlib API 1:1 so existing code needs only an import-path change to adopt it. Tech Stack Pure Python, zero required runtime dependencies (the lxml module is only exercised if the optional lxml package is already installed by the consumer), packaged with a standard setup.py/pyproject.toml. Code Quality tests.py at the repository root exercises each of the guarded parsers against a xmltestdata/ corpus of known attack payloads (entity bombs, external entity references, quadratic blowup), with CI historically run via Travis and coverage tracked via Codecov (badges in the README); the project also maintains a SECURITY.md documenting its threat model and disclosure process. API Design Because every module mirrors its stdlib counterpart’s function names and signatures exactly, the learning curve is close to zero — the entire integration is typically a single changed import line, with the tradeoff that some rarely-needed stdlib XML features are deliberately unavailable if they can’t be made safe.

Used by 14 apps in this directory

Python
59%
Apache 2.0

argilla

AI Development · Data Engineering

5,081

Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.

View details
65
Repo Health
81
Technical
63
Dependency
Built with
Python59%
Jupyter Notebook21%
Updated 2 days ago
Python
54%
Other

authentik

Authentication · Security

24,980

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
68
Dependency
Built with
Python54%
TypeScript33%
Updated today
Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

36,555

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
77
Repo Health
82
Technical
70
Dependency
Built with
Python51%
TypeScript36%
Updated 2 weeks ago
Python
83%
Apache 2.0

knowhere

AI Development · Developer Tools

2,515

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
70
Dependency
Built with
Python83%
HTML16%
Updated today
TypeScript
38%
Apache 2.0

Label Studio

AI Development · Data Engineering

28,083

Label Studio is an open-source, multi-type data labeling platform that lets teams annotate images, text, audio, video, and time series data with a configurable XML-based UI and export annotations in formats ready for any ML framework.

View details
93
Repo Health
87
Technical
68
Dependency
Built with
TypeScript38%
JavaScript27%
Python25%
Updated today
Python
68%
MIT

Langflow

AI Agents · AI Development

153,450

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
66
Dependency
Built with
Python68%
TypeScript22%
Updated today
Python
51%
AGPL 3.0

LearnHouse

Learning Management · CMS

2,178

Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.

View details
89
Repo Health
77
Technical
67
Dependency
Built with
Python51%
TypeScript48%
Updated 3 days ago
C++
66%
Other

Memgraph

Databases · AI Development

4,347

High-performance in-memory graph database for AI context and real-time analytics

View details
90
Repo Health
79
Technical
70
Dependency
Built with
C++66%
Python18%
Updated today
Python
100%
Other

OpenBB

Databases · Analytics · Invoicing Finance

72,027

The AI Workspace for Finance: Connect Data, Run AI Agents, Build Analytics

View details
82
Repo Health
80
Technical
68
Dependency
Built with
Python100%
Updated 2 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search