{"id":10177,"library":"pyxb-x","title":"PyXB-X","description":"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.","status":"maintenance","version":"1.2.6.3","language":"en","source_language":"en","source_url":"https://github.com/PyXB/pyxb","tags":["XML","Schema","Code Generation","SOAP","WSDL"],"install":[{"cmd":"pip install pyxb-x","lang":"bash","label":"Install PyXB-X"}],"dependencies":[],"imports":[{"note":"PyXB-X uses the `pyxb_x` namespace, not `pyxb`.","wrong":"from pyxb.gen.pyxbgen import PyXBGenerator","symbol":"PyXBGenerator","correct":"from pyxb_x.gen.pyxbgen import PyXBGenerator"},{"note":"Accessing core binding classes requires the `pyxb_x` namespace.","wrong":"import pyxb.binding.basis","symbol":"binding_basis","correct":"import pyxb_x.binding.basis"},{"note":"This function is automatically generated into your binding module to parse XML.","symbol":"CreateFromDocument","correct":"import my_generated_bindings_module\nparsed_obj = my_generated_bindings_module.CreateFromDocument(xml_data)"}],"quickstart":{"code":"import os\nimport sys\nimport subprocess\nimport tempfile\nimport shutil\n\n# 1. Define a simple XML Schema (XSD)\nxsd_content = \"\"\"<?xml version=\\\"1.0\\\"?>\n<xs:schema xmlns:xs=\\\"http://www.w3.org/2001/XMLSchema\\\">\n  <xs:element name=\\\"person\\\">\n    <xs:complexType>\n      <xs:sequence>\n        <xs:element name=\\\"name\\\" type=\\\"xs:string\\\"/>\n        <xs:element name=\\\"age\\\" type=\\\"xs:int\\\"/>\n      </xs:sequence>\n    </xs:complexType>\n  </xs:element>\n</xs:schema>\n\"\"\"\n\n# 2. Set up temporary directory for XSD and generated bindings\ntemp_dir = tempfile.mkdtemp()\nxsd_path = os.path.join(temp_dir, 'example.xsd')\nwith open(xsd_path, 'w') as f:\n    f.write(xsd_content)\n\nbinding_module_name = 'my_example_bindings'\noutput_dir = temp_dir\n\n# 3. Use pyxbgen to generate Python bindings\n#    The `pyxbgen` command-line tool is installed with `pyxb-x`.\n#    If `pyxbgen` is not found in PATH, use `python -m pyxb_x.gen.pyxbgen`.\n\n# Determine the correct command for pyxbgen\ntry:\n    subprocess.check_call(['pyxbgen', '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n    pyxbgen_cmd = 'pyxbgen'\nexcept (subprocess.CalledProcessError, FileNotFoundError):\n    pyxbgen_cmd = [sys.executable, '-m', 'pyxb_x.gen.pyxbgen']\n\ngenerate_command_args = [\n    f'--schema-location={xsd_path}',\n    '--binding-language=python',\n    f'--module={binding_module_name}',\n    f'--output-directory={output_dir}'\n]\n\nfull_command = [pyxbgen_cmd] + generate_command_args if isinstance(pyxbgen_cmd, list) else [pyxbgen_cmd] + generate_command_args\n\nprint(f\"Running generation command: {' '.join(full_command)}\")\nsubprocess.check_call(full_command)\nprint(f\"Bindings generated to: {output_dir}/{binding_module_name}.py\")\n\n# 4. Add the output directory to sys.path to import the generated module\nsys.path.insert(0, output_dir)\n\n# 5. Import and use the generated bindings\nimport my_example_bindings\n\n# Create an instance of the 'person' element\np = my_example_bindings.person(name=\"Alice\", age=30)\n\n# Serialize to XML\nxml_doc = p.toxml('utf-8', element_name='person')\nprint(\"\\nGenerated XML:\")\nprint(xml_doc.decode('utf-8'))\n\n# Parse XML back into a Python object\nparsed_p = my_example_bindings.CreateFromDocument(xml_doc)\nprint(f\"\\nParsed back: Name={parsed_p.name}, Age={parsed_p.age}\")\n\n# Clean up temporary files\nshutil.rmtree(temp_dir)\nprint(\"\\nCleaned up temporary files.\")","lang":"python","description":"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."},"warnings":[{"fix":"Change `import pyxb...` to `import pyxb_x...` for all PyXB-related imports.","message":"PyXB-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.","severity":"gotcha","affected_versions":"All versions of `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.","message":"PyXB-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`.","severity":"breaking","affected_versions":"All versions of `pyxb-x`."},{"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.","message":"Complex 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.","severity":"gotcha","affected_versions":"All versions."}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change the import statement from `import pyxb.binding` to `import pyxb_x.binding` (or similarly for other `pyxb` sub-modules).","cause":"Attempting to import from the original `pyxb` namespace instead of `pyxb_x`, which is where PyXB-X installs its modules.","error":"ModuleNotFoundError: No module named 'pyxb.binding'"},{"fix":"Verify the XML tag names (including case and namespace) against the generated Python binding class attributes. Ensure required elements are present in the XML. Refer to the generated binding code (`.py` files) for exact attribute names. Use `toxml()` on sample data to debug serialization/deserialization issues.","cause":"Mismatch between the XML element name (case-sensitive) or namespace, and the generated Python attribute name. This can also occur if an optional element is expected but not present in the XML data.","error":"AttributeError: 'MyGeneratedElement' object has no attribute 'some_sub_element'"},{"fix":"First, ensure `pyxbgen` is installed and accessible (it should be in your virtual environment's `bin` or `Scripts` folder after `pip install pyxb-x`). If it's not directly executable, try running it with `python -m pyxb_x.gen.pyxbgen` instead of just `pyxbgen`. Then, validate your XSD schema for correctness and double-check all command-line arguments.","cause":"The `pyxbgen` command-line tool was either not found in your system's PATH, or there was an error in the provided XSD file or command-line arguments.","error":"subprocess.CalledProcessError: Command '['pyxbgen', '--schema-location=...', ...]' returned non-zero exit status 1."}]}