Codegen types for the python client?

This may be a crazy request and I'm new to python so I don't even know if this is impossible or very difficult. But I'm using Python on some parts of our backend that require some of the data/ML heavy logic. I'm curious if it'd be possible to get the types from convex into my python backend.
11 Replies
ballingt
ballingt2y ago
Do you want static types in your editor, or tab completion in IPython/Jupyter? This isn't so wild of a request! We thought about this as we designed Convex to make it possible. It's helpful to hear you ask for it! Do you use input validation for the functions you use from Python?
Chad Maycumber
Chad MaycumberOP2y ago
Yeah we do use input validation with pydantic. I'm mostly looking for static types in the editor
ballingt
ballingt2y ago
Do you use the .input() input validation in the Convex functions that you call from Python?
ian
ian2y ago
@ballingt do you mean the args parameter of mutation / query/ action?
ballingt
ballingt2y ago
Ah whoops, yes! Wondering if @Chad Maycumber is using the { args: { a: v.string() }, handler: ()=>{} } args validation syntax in Convex functions.
Chad Maycumber
Chad MaycumberOP2y ago
Yes I am! I have a wrapper that requires the format
ballingt
ballingt2y ago
@Chad Maycumber awesome, then (we still need to write it but) you're not far from having codegen for Python. Decyphering TypeScript types is trickier but if you're using args it's not as difficult. It still may be a while before we get there.
Chad Maycumber
Chad MaycumberOP2y ago
Would be super cool to have “full” type safety even between my Python backend and typescript codebase. For context the Python api is using fastapi which we use to get a typescript client for the open api spec so this would be the last price of the puzzle!
jamwt
jamwt2y ago
@Chad Maycumber if you don't mind me asking, what part of your project is in python? (we're always curious to learn more about the circumstances when folks are calling convex from a python environment)
Chad Maycumber
Chad MaycumberOP2y ago
Langchain + data libraries mainly. The decision for was based around the fact that I didn’t want to rebuild some of the existing features they offer in JavaScript + running custom LLMs on a GPU
jamwt
jamwt2y ago
gotcha! yeah, I think the python langchain lib is still a lot more mature than langchain.js as well, so probably smart call

Did you find this page helpful?