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.
16 Replies
ballingt
ballingt3y 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 MaycumberOP3y ago
Yeah we do use input validation with pydantic. I'm mostly looking for static types in the editor
ballingt
ballingt3y ago
Do you use the .input() input validation in the Convex functions that you call from Python?
ian
ian3y ago
@ballingt do you mean the args parameter of mutation / query/ action?
ballingt
ballingt3y 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 MaycumberOP3y ago
Yes I am! I have a wrapper that requires the format
ballingt
ballingt3y 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 MaycumberOP3y 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
jamwt3y 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 MaycumberOP3y 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
jamwt3y ago
gotcha! yeah, I think the python langchain lib is still a lot more mature than langchain.js as well, so probably smart call
joey
joey2w ago
Same here: we had built out a Python FastAPI backend service + nextJS service, using openAPI to translate. Now we are migrating to Convex and would love to have just one schema in convex with generated types for both languages
ian
ian2w ago
You can generate an OpenAPI spec from your public API, then translate that to python. npx convex-helpers open-api-spec
sandias42
sandias426d ago
+1 to types in python! any updates on this? Also curious where can I read more about the openAPI spec generation @ian ? Is it the same as https://docs.convex.dev/client/open-api ? If so, it sounds like that loses reactive updates right, so the client.subscribe functionality of the existing python client would be sad?
OpenAPI & Other Languages | Convex Developer Hub
Convex doesn’t have explicit support for many languages including Go, Java, and
ian
ian6d ago
Yes that's the one. and btw there's now npx convex function-spec for the openapi types. The reactive updates still work in python - re-generating the types is still a manual process. the openapi spec is for all the query/mutation/etc. not just the http actions Someone has gotten auto-generation of types working I believe - thread in https://github.com/get-convex/convex-helpers/issues/759
GitHub
[Feat] Add watch support to ts-api-spec and open-api-spec · ...
I'm in the process of creating a convex client for dart. To my knowledge, other than the typescript client, none have a type generator. I'm parsing the generated ts-api-spec and generating ...
sandias42
sandias424d ago
excellent!!!

Did you find this page helpful?