Closed tlambert03 closed 7 months ago
@tlambert03 we seem to keep running into each other...
I was thinking of you and ome-types when I found this library.
I know! fancy seeing you here 👋
yes... I too have been kicking myself for not finding it earlier!
i butchered your bindings test to parametrize it with the BaseModel variant, just as a proof of principle. I can clean that up if you're actually interested in including this...
@Nicholas-Schaub, if you want to kick this around a little, I made a new repo to play with for now: https://github.com/tlambert03/xsdata-pydantic-basemodel
pip install git+https://github.com/tlambert03/xsdata-pydantic-basemodel.git
and then use --output pydantic-basemodel
What bindings test?
Sorry, that was a note to @tefra
So this is a hybrid dataclass + pydantic base model right?
I really want to use pure pydantic models if possible, I honestly don't have the time to work on this for a few more months, so any contribution is welcome.
yep, it's all working great in ome-types, and it's even working for pydantic v2 with a nice speed bump. Not a hybrid per-se, they are all pure BaseModel (no dataclass
decorators). I wasn't sure how soon you'd get around to this, so I've been developing it as a package that just gets shipped with ome-types
for now (so as not to clutter pypi with new package names).
You can see what I've got in this directory (and also in https://github.com/tlambert03/xsdata-pydantic-basemodel ... which lacks a few of the updates in ome-types)
To me, the big question is whether you'd (personally) want to have this BaseModel
variant in this library, perhaps with a switch in the config to decide whether to use BaseModel
or pydantic.dataclasses
, or if you think it's different enough to just make a new package.
I finally managed to pass the suite with pydantic 2.6
I also found myself wanting a pydantic.BaseModel subclass, as @Nicholas-Schaub requested in #17 ...
This is my stab at it. I was able to use it to convert a pretty large model, and bind relatively complicated XML data using the generated model, so I don't think it's too far off... but perhaps that's naive, given how different it is from the existing patterns.
@tefra, would love to get your input on this. Obviously, there are some discussions to be had about namespaces and exposing it, but probably best to pause here and see what you think