pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

pybind11 + pydantic

Open mariannasb opened this issue 3 years ago • 1 comments

Required prerequisites

  • [X] Make sure you've read the documentation. Your issue may be addressed there.
  • [X] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
  • [X] Consider asking first in the Gitter chat room or in a Discussion.

Problem description

I want to use classes generated through pybind11 for pydantic basemodels but I'm having trouble getting that to work.

pydantic seems to have support for using NamedTuples or TypedDicts, but my classes dont seem to be either, I dont know if it is possible to get pybind11 to make them like that?

And I have also found people doing it by casting their classes as pydantic dataclasses: https://stackoverflow.com/questions/68651305/create-a-pydantic-basemodel-definition-with-external-class-or-dictionary

But that approach didn't work either for me, I get pydantic models but they seem to be empty, no variables. So I expect that is something missing from the generated classes, or just not the way pydantic expects it to be.

Reproducible example code

No response

mariannasb avatar Oct 13 '22 11:10 mariannasb