pybind11 + pydantic
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the pybind11 documentation and the reported Pydantic integration approaches. Build a minimal reproducible example, since none is included, and determine whether bound classes can expose the structure Pydantic requires. Done should be a clear compatibility result with documented behavior or a narrowly defined implementation path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100