-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explore where pydantic
might help with UX
#2860
Comments
I think this idea is great for runtime type checking. The objects need to inherit from |
I'm very much looking forward to this feature. In my work, I encapsulate a bunch of pydantic Models outside of But actually there are some problems here. In my work, I use Also, |
Nice to see some discussion on this already! @e3243eric I opened this as more of an exploratory "research" issue to track pros, cons, possible improvements, etc. There's not a real void to be filled with a PR quite yet but happy to see the interest coming in for it! @XiaoHuiHui233, thanks for getting the conversation started and providing some solid input here. Very much appreciated. Looks like some benchmarking could be useful. It might be nice to benchmark on a subset of calls / types to compare against the current state of things. Yeah, looks like V2 release is slated for Q1 of 2023 - will be good to keep an eye out for it. I don't quite have the bandwidth to dive in here at the moment but being as this would likely be part of the next major version of web3.py ( |
That's funny, I was literally thinking about this earlier but was worried about pushback on adding another dependency. Would the idea be that this replaces |
I've built a library that takes an approach similar to FastAPI, where the library is built on top of Pydantic and all types are BaseModels. https://github.com/empyrealapp/eth-packages is the repo if you want to check it out. I've found using Pydantic has a lot of benefits, especially in indexing contract events and creating typed function bindings. I think if the team finds this as a P4 priority, I'm happy to offer the work I've been doing as a friendly alternative to web3.py that addresses some of these requirements. I'd also like to share some of my findings if there is interested in integrating Pydantic. The biggest benefits I found was utilizing Generics for contract functions to remove the need for contract ABIs, and having typed Events for indexing so it's much less error prone when you're building a larger indexing project. For example, I had much better success with my indexing of UniswapV2/V3 using my library because I was able to catch most of my bugs using mypy. |
Another potential suggestion is Edit: Apparently one reason it's more performant is that it doesn't perform validation on object creation, only on export. That may violate the intent of this issue's goal, but I leave it here just in case. |
Explore the idea of using
pydantic
dependency to better validate request object types and their params. This could help with field validation and error messages. There may be some UX improvements that are worth exploring there.The text was updated successfully, but these errors were encountered: