Hosna Qasmei
Hosna Qasmei11mo ago

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
jamwt
jamwt11mo ago
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
ballingt
ballingt11mo ago
@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?
Hosna Qasmei
Hosna QasmeiOP11mo ago
yes, I am trying to add a row to my database. I found this example https://github.com/get-convex/convex-py
ballingt
ballingt11mo ago
This looks about like the Python Quickstart https://docs.convex.dev/quickstart/python, just
from convex import ConvexClient
client = ConvexClient("CONVEX_URL_GOES_HERE")
print(client.query("tasks:get"))
from convex import ConvexClient
client = ConvexClient("CONVEX_URL_GOES_HERE")
print(client.query("tasks:get"))
Hosna Qasmei
Hosna QasmeiOP11mo ago
right, im stuck on mutation cant find and example for it
ballingt
ballingt11mo ago
if you're submitting data, then client.mutation("yourFile:yourMutation", {data: 123})
Hosna Qasmei
Hosna QasmeiOP11mo ago
so in the example it says that tasks.js is located in side the convex folder where would i put that? in jupyter notebook?
ballingt
ballingt11mo ago
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)
Hosna Qasmei
Hosna QasmeiOP11mo ago
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
ballingt
ballingt11mo ago
Great! Would love to hear about what you do with it.
Hosna Qasmei
Hosna QasmeiOP11mo ago
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?
ballingt
ballingt11mo ago
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.
Hosna Qasmei
Hosna QasmeiOP11mo ago
Oh okay gotcha, that’s what I’m missing. It’s not been deployed just been running locally.
ballingt
ballingt11mo ago
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.

Did you find this page helpful?