Description
Goal: (1) Make (pydantic-core
->) pydantic
blazingly fast. (2) Make pydantic a dataclass interface for PyO3.
My previous issue made me consider generating Rust struct
s for Pydantic models. Rust doesn't support defining struct
at runtime through macro
, our only route is to generate the Rust code and compile it ourselves.
My solution
Generate Rust code from a pydantic.BaseModel
derived model (or model in short), and compile it at runtime during development. In production, there are several avenues: Compile automatically using a dedicated CLI
the binaries would be outputed to the package. Another interesting avenue for compilation is to define these settings in pyproject.toml
-> tool.pydantic
:
[tool.pydantic]
targets = ["x86", "arm", "etc"]
The compilation would be once per model, and validation would be handled by Rust entirely.
I'd like to take this on later this year if someone else hasn't by that time (appreciate the credit if you use my idea). This should be discussed ahead of an implementation, so I am starting the discussion here, I think it is the right place to do so.
Considerations
Definitely use something like rs codegen
.