Python bindings for the Uppsala XML library
Project description
pyuppsala
Python bindings for the Uppsala XML library -- a zero-dependency, pure-Rust implementation of XML 1.0, Namespaces, XPath 1.0, and XSD validation.
pyuppsala gives you a fast, correct, and memory-safe XML toolkit from Python with no C dependencies to compile and no transitive native libraries to audit.
Features
- XML 1.0 parsing with full well-formedness checking
- Namespace-aware DOM with tree mutation (create, append, insert, remove, detach)
- XPath 1.0 evaluation (all axes, functions, predicates)
- XSD validation (structures + datatypes, 40+ built-in types, facets, complex types)
- XSD regex pattern matching (Unicode categories, blocks, character class subtraction)
- Imperative XML builder (
XmlWriter) for constructing output without a DOM - Serialization with pretty-printing, compact output, and streaming to files
- Automatic encoding detection for UTF-8 and UTF-16 (LE/BE)
Installation
python3 -m pip install pyuppsala
Or with uv:
uv add pyuppsala
Wheels are compiled from Rust via maturin. Python 3.10+ is required.
Quick start
Parse and query
from pyuppsala import Document, XPathEvaluator
doc = Document("<bookstore><book><title>Moby Dick</title></book></bookstore>")
doc.prepare_xpath()
xpath = XPathEvaluator()
title = xpath.evaluate(doc, "string(//title)")
print(title) # "Moby Dick"
Build XML
from pyuppsala import XmlWriter
w = XmlWriter()
w.write_declaration()
w.start_element("catalog", [("xmlns", "urn:example")])
w.start_element("item", [("id", "1")])
w.text("Widget")
w.end_element("item")
w.end_element("catalog")
print(w.to_string())
Validate against an XSD schema
from pyuppsala import XsdValidator
schema = """\
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="greeting" type="xs:string"/>
</xs:schema>
"""
validator = XsdValidator(schema)
print(validator.is_valid_str("<greeting>Hello!</greeting>")) # True
print(validator.is_valid_str("<greeting><bad/></greeting>")) # False
Mutate the DOM
from pyuppsala import Document
doc = Document("<root><a/></root>")
root = doc.document_element
b = doc.create_element("b")
doc.append_child(root, b)
print(doc.to_xml()) # <root><a/><b/></root>
XSD regex
from pyuppsala import XsdRegex
regex = XsdRegex(r"[0-9]{5}")
print(regex.is_match("12345")) # True
print(regex.is_match("abcde")) # False
API overview
| Class / function | Purpose |
|---|---|
Document(xml) |
Parse XML string into a DOM |
Document.from_bytes(data) |
Parse XML bytes (auto-detects UTF-8/UTF-16) |
Document.empty() |
Create an empty document for building from scratch |
Node |
A handle to a node in the document tree |
QName |
A qualified XML name (local name + optional namespace + prefix) |
Attribute |
An XML attribute (name + value) |
XPathEvaluator |
Evaluate XPath 1.0 expressions |
XsdValidator(schema) |
Validate documents against an XSD schema |
XmlWriter |
Imperative XML builder (no DOM needed) |
XsdRegex(pattern) |
XSD regular expression pattern matcher |
parse(xml) |
Module-level shorthand for Document(xml) |
parse_bytes(data) |
Module-level shorthand for Document.from_bytes(data) |
Exceptions
| Exception | Raised when |
|---|---|
XmlParseError |
XML is syntactically malformed |
XmlWellFormednessError |
XML violates well-formedness constraints |
XmlNamespaceError |
Namespace prefix is undeclared or misused |
XPathError |
XPath expression is invalid |
XsdValidationError |
XSD schema itself is invalid |
All exceptions inherit from Exception.
Type stubs
A pyuppsala.pyi file is included for full IDE auto-completion and
type-checking with mypy/pyright.
Development
# Clone the repository
git clone https://github.com/kushaldas/pyuppsala.git
cd pyuppsala
# Set up the environment with uv
uv sync
# Build the native extension in development mode
uv run maturin develop
# Run the test suite
uv run pytest
# Build a release wheel
uv run maturin build --release
License
BSD-2-Clause
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyuppsala-0.3.0.tar.gz.
File metadata
- Download URL: pyuppsala-0.3.0.tar.gz
- Upload date:
- Size: 59.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2c41c9d46e3707101991f312faa444718782877b70395d7a24cb3dacc874c74
|
|
| MD5 |
456025061bec024015c80534a70f0df0
|
|
| BLAKE2b-256 |
7a0013e2389ebacbd1157d25e4825926cde0cb0fdc3f31592c2379a33e2eb425
|
Provenance
The following attestation bundles were made for pyuppsala-0.3.0.tar.gz:
Publisher:
release.yml on kushaldas/pyuppsala
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyuppsala-0.3.0.tar.gz -
Subject digest:
a2c41c9d46e3707101991f312faa444718782877b70395d7a24cb3dacc874c74 - Sigstore transparency entry: 1039872390
- Sigstore integration time:
-
Permalink:
kushaldas/pyuppsala@38eacfc6b442fa8dd55554da9aa1af40400e13b7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kushaldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@38eacfc6b442fa8dd55554da9aa1af40400e13b7 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pyuppsala-0.3.0-cp310-abi3-win_arm64.whl.
File metadata
- Download URL: pyuppsala-0.3.0-cp310-abi3-win_arm64.whl
- Upload date:
- Size: 579.6 kB
- Tags: CPython 3.10+, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1a0f1e316077a8e0c78348bd0fb45c348cf217f71181bab1ad5c8687d66005d
|
|
| MD5 |
02980a68daa42613b7b18bee491c820a
|
|
| BLAKE2b-256 |
38fa95b9dded640fb1ac49e2f71b83467eb1d08bfd990a1caa9d6c3617e81a31
|
Provenance
The following attestation bundles were made for pyuppsala-0.3.0-cp310-abi3-win_arm64.whl:
Publisher:
release.yml on kushaldas/pyuppsala
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyuppsala-0.3.0-cp310-abi3-win_arm64.whl -
Subject digest:
f1a0f1e316077a8e0c78348bd0fb45c348cf217f71181bab1ad5c8687d66005d - Sigstore transparency entry: 1039872789
- Sigstore integration time:
-
Permalink:
kushaldas/pyuppsala@38eacfc6b442fa8dd55554da9aa1af40400e13b7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kushaldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@38eacfc6b442fa8dd55554da9aa1af40400e13b7 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pyuppsala-0.3.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: pyuppsala-0.3.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 607.9 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3b5946cb3729e6c4d642af630f81732a88842821d67247f7f410052db1329aa
|
|
| MD5 |
8d7863529abd54a35ebdff71f4507509
|
|
| BLAKE2b-256 |
35132d131d9dca81b3d82447613aea0078ba8ee6ec0a28c2c7ce48eac4b6ad47
|
Provenance
The following attestation bundles were made for pyuppsala-0.3.0-cp310-abi3-win_amd64.whl:
Publisher:
release.yml on kushaldas/pyuppsala
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyuppsala-0.3.0-cp310-abi3-win_amd64.whl -
Subject digest:
f3b5946cb3729e6c4d642af630f81732a88842821d67247f7f410052db1329aa - Sigstore transparency entry: 1039872598
- Sigstore integration time:
-
Permalink:
kushaldas/pyuppsala@38eacfc6b442fa8dd55554da9aa1af40400e13b7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kushaldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@38eacfc6b442fa8dd55554da9aa1af40400e13b7 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pyuppsala-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyuppsala-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 687.9 kB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22d2e4d9c0ec9960342405e6491db80e4f571198e0e9fb15c2db38bba3c751b6
|
|
| MD5 |
f20712fc260f20497c9f57e16c8cae69
|
|
| BLAKE2b-256 |
a598f4d612e3ea40526fc4f09df64c12d2c448a6f48a839cb7dad637ea7cfccc
|
Provenance
The following attestation bundles were made for pyuppsala-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl:
Publisher:
release.yml on kushaldas/pyuppsala
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyuppsala-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
22d2e4d9c0ec9960342405e6491db80e4f571198e0e9fb15c2db38bba3c751b6 - Sigstore transparency entry: 1039872502
- Sigstore integration time:
-
Permalink:
kushaldas/pyuppsala@38eacfc6b442fa8dd55554da9aa1af40400e13b7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kushaldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@38eacfc6b442fa8dd55554da9aa1af40400e13b7 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pyuppsala-0.3.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: pyuppsala-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 624.4 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c949de4aa0f4079a6e4b120ce0bf92be0971238b738a6e26e22745678283fc55
|
|
| MD5 |
56ab93aa3dd611da81b46651ca307ff4
|
|
| BLAKE2b-256 |
e8f9b0e8f3e5a48a2d67ec031bd52e0be1a18984545ec38e54e600756b57e665
|
Provenance
The following attestation bundles were made for pyuppsala-0.3.0-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on kushaldas/pyuppsala
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyuppsala-0.3.0-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
c949de4aa0f4079a6e4b120ce0bf92be0971238b738a6e26e22745678283fc55 - Sigstore transparency entry: 1039872700
- Sigstore integration time:
-
Permalink:
kushaldas/pyuppsala@38eacfc6b442fa8dd55554da9aa1af40400e13b7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kushaldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@38eacfc6b442fa8dd55554da9aa1af40400e13b7 -
Trigger Event:
workflow_dispatch
-
Statement type: