{"id":22998,"library":"xsdata-pydantic","title":"xsdata-pydantic","description":"xsdata-pydantic is a plugin for xsdata that generates Pydantic models from XML Schema (XSD) documents. It provides a code generator producing Python classes with Pydantic v1 or v2 support, data binding, and serialization. The current version is 24.5, compatible with Python >=3.8 and xsdata >=22.10. Release cadence is irregular.","status":"active","version":"24.5","language":"python","source_language":"en","source_url":"https://github.com/tefra/xsdata-pydantic","tags":["xsdata","pydantic","xml","xsd","code-generation","data-binding"],"install":[{"cmd":"pip install xsdata-pydantic","lang":"bash","label":"Install xsdata-pydantic"}],"dependencies":[{"reason":"Core library for XML data binding and code generation.","package":"xsdata","optional":false},{"reason":"Required for model generation and runtime validation.","package":"pydantic","optional":false}],"imports":[{"note":"The plugin is a separate package; importing from xsdata will fail.","wrong":"from xsdata.plugins import PydanticExtension","symbol":"PydanticExtension","correct":"from xsdata_pydantic import PydanticExtension"}],"quickstart":{"code":"from xsdata_pydantic import PydanticExtension\nfrom xsdata.formats.dataclass.serializers import XmlSerializer\nfrom xsdata.formats.dataclass.parsers import XmlParser\n\n# Generate models from XSD using CLI or code generator\n# Example: xsdata my-schema.xsd --package mypackage --extension PydanticExtension\n\n# After generation, use parser and serializer\nparser = XmlParser()\nserializer = XmlSerializer()","lang":"python","description":"Install the plugin, generate Pydantic models using xsdata CLI with the extension, then parse and serialize XML data."},"warnings":[{"fix":"Use 'from xsdata_pydantic import PydanticV1Extension' and pass it as the extension.","message":"In version 24.x, Pydantic v2 is the default. If you need Pydantic v1, you must explicitly set the extension with PydanticV1Extension.","severity":"breaking","affected_versions":">=24.0"},{"fix":"Use XmlSerializer from xsdata to serialize to XML, or convert to dict/list manually.","message":"The generated models are dataclasses with Pydantic validation. They cannot be directly used with raw Pydantic BaseModel methods like .model_dump_json(). Use the xsdata XmlSerializer instead.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to Python 3.9 or later.","message":"Python 3.8 support will be dropped in a future release. Ensure you use Python 3.9+ for new projects.","severity":"deprecated","affected_versions":">=24.5"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'pip install xsdata-pydantic'","cause":"The package is not installed or installed under a different name.","error":"ModuleNotFoundError: No module named 'xsdata_pydantic'"},{"fix":"Upgrade xsdata-pydantic to version 24.0+: 'pip install --upgrade xsdata-pydantic'","cause":"Using an older version (<24.0) where the extension was named differently or not yet introduced.","error":"AttributeError: module 'xsdata_pydantic' has no attribute 'PydanticExtension'"},{"fix":"Use xsdata's renaming feature: add '--field-name-policy' or customize the generator to rename conflicting fields.","cause":"XML schema has an element named 'type' which conflicts with Pydantic's built-in type field.","error":"pydantic.errors.PydanticUserError: Field name \"type\" shadows a BaseModel attribute; use a different field name"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}