Jupyter Notebook + Convex
Wanted to know if it's possible to use convex to upload a value into a table from values calculated using python in Jupyter Notebook?
It seems like there isn't because you have to be running the convex server, just wanted to double check.
14 Replies
heh. believe it or not, @ballingt just demonstrated something like this in our show and tell like 40 minutes ago
using the new python client that's about to go out
@Hosna Qasmei You can use the
convex
client from jupyter to read query results and run mutations and actions — can you say more about your use case?yes, I am trying to add a row to my database.
I found this example
https://github.com/get-convex/convex-py
right, im stuck on mutation
cant find and example for it
if you're submitting data, then
client.mutation("yourFile:yourMutation", {data: 123})
so in the example it says that tasks.js is located in side the convex folder
where would i put that? in jupyter notebook?
Ah I see, yeah you will need to create a Convex project and write a bit of TypeScript for it.
Then the Jupyter notebook can be anywhere — it doesn't import anything from the
convex/
directory, and the Python client isn't typed to your API, you just you strings to specify the mutation name.
You can take any existing Convex deployment and use the Python Convex client to communicate with it from any Jupyter notebook, there's no need to have the files together.
(you may want to add a shared secret argument to prevent anyone from running this mutation)ah okay i think i get what you mean let me try it right now
Yup, it works now thanks you @ballingt !
also side question though
Great! Would love to hear about what you do with it.
so i've been testing using jupyter notebook. but want to move to a python script that runs cron job every night to scrape data from a website, and upload it to my convex database.
So im assuming for this to work i have to always have my convex server running right?
Your Convex deployment is already always running, it's always ready to receive a mutation or HTTP request — even if it's your development deployment.
there are two servers to think about: your frontend server (often Next.js, Remix, Vite, etc.) and your Convex deployment. As long as you're using using Convex functions (vs e.g. Next.js api routes) this is always available because the deployment is always running.
Oh okay gotcha, that’s what I’m missing. It’s not been deployed just been running locally.
Cool, sounds like the Next.js or whatever frontend server isn't deployed, but the Convex deployment is always deployed — you can always talk to it.