Generate Protobuf definitions, JSON Schema, and Python XML-to-protobuf converters from XSD and DTD schemas.
Project description
XSDFormer
XSDFormer deforms XML schema definitions (XSDs) into Protobuf definitions. It also generates Python code to convert parsed XML into the corresponding Protobuf representation.
It supports enough of the XSD specification to convert the ClinVar and BioC schemas; full support for all XSD features is a non-goal.
Why convert from XSD to Protobuf?
While XML and XSDs (or alternatively JSON and JSON schemas) are powerful for defining complex, human-readable data structures, they have some drawbacks, especially in high-performance applications or when dealing with large datasets.
Performance and Size
- Parsing Speed: XML is a text-based format and can be slow to parse. Protobuf is a binary format that is designed for speed and efficiency. Converting XML data to Protobuf can result in significantly faster parsing times.
- Storage Space: XML is verbose, with opening and closing tags that add to the file size. Protobuf's binary format is much more compact, leading to smaller file sizes. This is a major advantage for storing large datasets or for transmitting data over a network. Effectively compressing XML requires a schema-specific dictionary, or compressing multiple records together so that the dictionary of tag/key names can be reused. However this limits the possibility for random access enabled by compressing records individually.
Developer Experience
- Generated Code: Protobuf compilers generate code in many languages, providing a simple and consistent way to work with the data.
- Type Safety: The Protobuf schema provides strong typing, which can help to prevent bugs. Parsing the wire format requires the protobuf definition, meaning that the data is tied to its typed representation. Conversely XML representations are only optionally validated by a schema, and so by default type information is lost during parsing (everything is treated as text).
By converting XSDs to Protobuf definitions, xsd-former allows
developers to take advantage of the benefits of Protobuf while still
working with data that is originally defined in an XML schema.
Output formats
From a single XSD (or DTD) source, XSDFormer can emit:
- Protobuf (
.proto) —--proto-out. - Python XML→protobuf converters —
--py-out/--py-module. - JSON Schema —
--json-schema-out(from the XSD, or directly from a.protovia theprotosubcommand). - TypeSpec (
.tsp) —--typespec-out(see below).
TypeSpec output
TypeSpec is a compact, authorable schema
language that fans out to OpenAPI, JSON Schema, and protobuf — and from
those to pydantic and zod. XSDFormer emits a .tsp so the same model
that backs the stored protobufs can also drive backend pydantic models
and frontend zod validators, all interconvertible.
# Default: clean, readable TypeSpec (string-valued enums, native scalars).
# Suited to pydantic/zod generation.
xsdformer xsd schema.xsd --typespec-out schema.tsp
# DTD sources work too (e.g. PubMed).
xsdformer dtd pubmed.dtd --typespec-out pubmed.tsp --proto-package pubmed
# proto-compat: adds @typespec/protobuf decorations (@package, @field,
# integer-valued enums) so `tsp -> proto` can be run as a regression
# check that it matches the directly generated proto.
xsdformer xsd schema.xsd --typespec-out schema.tsp --proto-compat
The .tsp is a derived artifact — regenerated from the XSD alongside
the proto, never hand-edited. The governing invariant is that
xsd → proto and xsd → tsp → proto agree at the wire/semantic level
(field numbers, field types, enum numbers); cosmetic differences
(oneof grouping, nested-vs-hoisted placement, comments, ordering) are
tolerated. See docs/adr/0001-typespec-output-format.md
for the full design.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 xsd_former-1.1.0.tar.gz.
File metadata
- Download URL: xsd_former-1.1.0.tar.gz
- Upload date:
- Size: 244.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5775800af2bed360dfb06082018675e96d7311b4be7306de0e1636a03f8661b0
|
|
| MD5 |
74cc4307510bd0a875e2e069e2287dd0
|
|
| BLAKE2b-256 |
78e18533aecb4ea02c648d0d1d6cfeeb9d06012606c86dbbe73933cb74baa0ef
|
Provenance
The following attestation bundles were made for xsd_former-1.1.0.tar.gz:
Publisher:
release.yml on populationgenomics/xsd-former
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xsd_former-1.1.0.tar.gz -
Subject digest:
5775800af2bed360dfb06082018675e96d7311b4be7306de0e1636a03f8661b0 - Sigstore transparency entry: 2084330528
- Sigstore integration time:
-
Permalink:
populationgenomics/xsd-former@752e39fd7896599048e33b9120bf5b298027300e -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/populationgenomics
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@752e39fd7896599048e33b9120bf5b298027300e -
Trigger Event:
release
-
Statement type:
File details
Details for the file xsd_former-1.1.0-py3-none-any.whl.
File metadata
- Download URL: xsd_former-1.1.0-py3-none-any.whl
- Upload date:
- Size: 51.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20e79d51b02cf706dfe096a6e9244d2e6c6e7c8c2fed1031be17abe44f5db3b5
|
|
| MD5 |
3965e82d65b6ef8e24aa7194d3c87369
|
|
| BLAKE2b-256 |
864df9a2c26c752dd7152fc963b595e6440e00636c6d8bb8b77d0e0f9bc8d91b
|
Provenance
The following attestation bundles were made for xsd_former-1.1.0-py3-none-any.whl:
Publisher:
release.yml on populationgenomics/xsd-former
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xsd_former-1.1.0-py3-none-any.whl -
Subject digest:
20e79d51b02cf706dfe096a6e9244d2e6c6e7c8c2fed1031be17abe44f5db3b5 - Sigstore transparency entry: 2084330547
- Sigstore integration time:
-
Permalink:
populationgenomics/xsd-former@752e39fd7896599048e33b9120bf5b298027300e -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/populationgenomics
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@752e39fd7896599048e33b9120bf5b298027300e -
Trigger Event:
release
-
Statement type: