Registry / serialization / pyxb-x

pyxb-x

JSON →
library1.2.6.3pypypi✓ verified 86d ago

PyXB-X ("pixbix") is a pure Python package that generates Python source code for classes that correspond to data structures defined by XMLSchema. It is a re-release of PyXB 1.2.6 under a distinct namespace (`pyxb_x`) to avoid dependency conflicts. The project appears to be in maintenance mode, with its last PyPI release in March 2020 and its upstream PyXB project showing limited recent activity.

pip install pyxb-x
INSTALL
IMPORT
SIG · PYXB-X
P
pyxb-x
serializationpythonv1.2.6.3
Install
1.8s avg
Import
—
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.2.6.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 20MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 1.8s · import 0.000s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BIND
✓ from pyxb import BIND
✗ from pyxb_x.gen.pyxbgen import PyXBGenerator
AbstractElementError
✓ from pyxb import AbstractElementError
BindingError
✓ from pyxb import BindingError

This quickstart demonstrates how to define a simple XML Schema (XSD), use the `pyxbgen` command-line tool to generate Python binding classes, and then use those classes to create Python objects, serialize them to XML, and parse XML back into objects.

import os import sys import subprocess import tempfile import shutil # 1. Define a simple XML Schema (XSD) xsd_content = """<?xml version=\"1.0\"?> <xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"> <xs:element name=\"person\"> <xs:complexType> <xs:sequence> <xs:element name=\"name\" type=\"xs:string\"/> <xs:element name=\"age\" type=\"xs:int\"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> """ # 2. Set up temporary directory for XSD and generated bindings temp_dir = tempfile.mkdtemp() xsd_path = os.path.join(temp_dir, 'example.xsd') with open(xsd_path, 'w') as f: f.write(xsd_content) binding_module_name = 'my_example_bindings' output_dir = temp_dir # 3. Use pyxbgen to generate Python bindings # The `pyxbgen` command-line tool is installed with `pyxb-x`. # If `pyxbgen` is not found in PATH, use `python -m pyxb_x.gen.pyxbgen`. # Determine the correct command for pyxbgen try: subprocess.check_call(['pyxbgen', '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) pyxbgen_cmd = 'pyxbgen' except (subprocess.CalledProcessError, FileNotFoundError): pyxbgen_cmd = [sys.executable, '-m', 'pyxb_x.gen.pyxbgen'] generate_command_args = [ f'--schema-location={xsd_path}', '--binding-language=python', f'--module={binding_module_name}', f'--output-directory={output_dir}' ] full_command = [pyxbgen_cmd] + generate_command_args if isinstance(pyxbgen_cmd, list) else [pyxbgen_cmd] + generate_command_args print(f"Running generation command: {' '.join(full_command)}") subprocess.check_call(full_command) print(f"Bindings generated to: {output_dir}/{binding_module_name}.py") # 4. Add the output directory to sys.path to import the generated module sys.path.insert(0, output_dir) # 5. Import and use the generated bindings import my_example_bindings # Create an instance of the 'person' element p = my_example_bindings.person(name="Alice", age=30) # Serialize to XML xml_doc = p.toxml('utf-8', element_name='person') print("\nGenerated XML:") print(xml_doc.decode('utf-8')) # Parse XML back into a Python object parsed_p = my_example_bindings.CreateFromDocument(xml_doc) print(f"\nParsed back: Name={parsed_p.name}, Age={parsed_p.age}") # Clean up temporary files shutil.rmtree(temp_dir) print("\nCleaned up temporary files.")
pyxbgen --version
Debug
Known issues
gotchaPyXB-X installs under the `pyxb_x` namespace, not `pyxb`. All imports must use `pyxb_x` (e.g., `import pyxb_x.binding`). If you have both `pyxb` and `pyxb-x` installed, ensure you are consistently using `pyxb_x` to avoid `ModuleNotFoundError` or conflicts.
fix
Change `import pyxb...` to `import pyxb_x...` for all PyXB-related imports.
affects: All versions of `pyxb-x`.
breakingPyXB-X specifically mirrors PyXB version 1.2.6. Be aware that any changes, new features, or breaking API modifications introduced in later conceptual versions of the upstream PyXB project are not present or compatible with `pyxb-x`.
fix
Stick to documentation and examples specific to PyXB 1.2.6 when using `pyxb-x`. Do not expect compatibility with features or APIs beyond that version.
affects: All versions of `pyxb-x`.
gotchaComplex XML Schema features (e.g., multiple namespaces, `xsi:type`, `anyURI` types, deeply nested hierarchies, wildcards) can sometimes result in unexpected Python bindings, generation errors, or runtime issues during serialization/deserialization.
fix
Simplify schemas where possible. Consult the PyXB 1.2.6 documentation thoroughly for handling advanced schema constructs. Debug generated code and use `toxml()` and `CreateFromDocument()` to test edge cases.
affects: All versions.
Upgrade
Version history
1.2.6.3latest on PyPI · released Jan 7, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
pyxb-x — pip install pyxb-x · libregistry