Convert XML Schema Definition files to voluptuous schemas.
Get it on PyPi:
pip install xsd-to-vol
Basic usage:
xml-to-vol -i schema.xsd -o schema.py
Basic pipe usage:
cat schema.xsd | xml-to-vol > schema.py
Pipe through black formatter:
cat schema.xsd | xsd-to-vol | black - > schema.py
Advanced piping example with curl:
curl -s https://api-test.geofox.de/gti/public/geofoxThinInterfacePublic.xsd 2>&1 | xsd-to-vol | black - > schema.py
You can also mix input/output files and stdin/stdout.
You can also use the xml_to_vol
method to convert your schema:
from xsd_to_vol import xsd_to_vol
with open("schema.xsd", 'r') as schema_file:
xsd = schema_file.read()
print(xsd_to_vol(xsd))
While the generation should work for most xsd files, there are some features I'd like to have in future versions:
- Only include used imports: Currently all possible voluptuous requirements are imported. The required imports can be determined.
- Tests: Gather different xsd schemas and build pytests to test the generation.
- Automatic code formatting: Run black over the code (without piping).
If you want to contribute to this, please read the Contribution guidelines