#Python Based Real-time connection

14 messages · Page 1 of 1 (latest)

sturdy delta
#

Hey any plans to make the https://github.com/get-convex/convex-py client library reactive. Something like a websocket handler like:

@on_change_query("file:rpc")
def on_change(query_result: QueryResult):
  # handle logic
@on_change_table("table...")
def on_change(record: RecordChangeEvent):
  # handle logic

I have some backend services that need python and would love it if there was a way for me to handle side effects in my python code. I know the workaround with actions, etc and pushing the behavior to my app but i would love it if the python portion of my code was also reactive! Thanks!

GitHub

Python Client Library for Convex. Contribute to get-convex/convex-py development by creating an account on GitHub.

tidal apexBOT
#

Thanks for posting in #1088161997662724167.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.

    - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
    - Use [search.convex.dev](https://search.convex.dev) to search Docs, Stack, and Discord all at once.
    - Additionally, you can post your questions in the Convex Community's #1228095053885476985 channel to receive a response from AI.
    - Avoid tagging staff unless specifically instructed.

    Thank you!
onyx wind
quasi meteor
#

@sturdy delta you could totally write a decorator that does this! You'd be subscribing to a Convex query function, not a table change—but that Convex query function can read whatever tables you want.

sturdy delta
#

oh wow blind of me 😦 i missed the subscribe option 😂 i saw the rest of the mutations and didnt realize there is a subscribe this is amazing!

quasi meteor
#

@sturdy delta are you using async Python? There's a PR for async iteration and I've thought about this, but right now whether you want to use threads or asyncio is up to you

sturdy delta
#

prefer asyncio i am currently running backend on modal functions. and i would like to dispatch containers for longer durable python code execution when a new entry happens.

quasi meteor
#

I've found it easiest to run a thread that blocks on the subscription updates and use threadsafe queues to get communicate back to the rest of process

#

Cool, shouldn't be hard to hook up with the usual asyncio adapters for blocking calls but I'd be interested in making this more convenient for cases like yours

sturdy delta
#

but standard loops also work. just curious based on the example when subscribing to a list query are the list of messages deduped or is the list query republish all the results to the python client

quasi meteor
#

Each time you get the entire new query result (so in that example, list of messages) so if you want to use it like a work queue you should write a Convex query function that returns all "unclaimed" tasks and have yorurPython server "claim" the task by writing to the DB

#

subscriptions in Convex are always on the result of a query funciton, so the naive way to get changes is to diff these results on the client (but that doesnt' scale well)

#

so you probably want to write a function that returns whichever entities you're intrested in, e.g. "job.status === 'unclaimed'"

sturdy delta
#

cool this is pretty slick... to scale out large jobs that require gpus/multiple cores... with very little code and logic!