How to perform calculation outside of Bubble?

Dear Bubble Community,

I am currently trying to calculate something outside of Bubble.io using the data inside my Bubble.io app. I think that the calculation that I am trying to perform is not possible inside Bubble.io. Even if it was, I want the flexibility to create my own Python scripts for specific purposes.

Let’s take a simple example such as computing the average of a list. I want to pass a list stored in my Bubble app to a Python script that will compute the average and then send back the result to the Bubble app. How should I do ?

I have thought about creating a get_average endpoint in my Python app that takes as an input the list and returns the output (without storing any data). Then I would use a API request from Bubble to perform the calculations. What do you think about that ?

Best Regards,

Quentin

PS: Just so we are clear, the real purpose is not computing an average

Hey @quentin.barbato , natively bubble don’t offer way to run python script.
It would be better if you host your script on ec2 instance and call it from there!

Thanks for taking the time to answer.
I know that is not possible to run Python scripts on Bubble.
I will try to formulate my question in another way.
What workflow should I trigger from Bubble to perform calculation using an external Python app ? Is it an API workflow ? In my case I am not using ec2 instance, I am on PythonAnywhere.

Yes, you need to use the backend workflow here.
Using “Schedule an API” workflow event > Detect request

First you need to hit the initialize URL given by detect request, and next you’re good to set the api with it.

2 Likes

I do this using javascript/node and the Google Cloud Functions all the time. When you make the serverless function, you should make it HTTPS callable. you can then use that trigger URL in the API connector. Depending on how you want to use it, you may set it to be of type data OR action. Data lets you call the api data and feed it to an element or other input. action lets you use the call as a step in a workflow and it’s output can be used in subsequent steps like Step 1's API Calls Data

2 Likes

Both of your answers helped me a lot.
Thanks a lot for the help.

1 Like

For Bulk data it may be an issue to trigger an api workflow as it may timeout. This is where the Bubble Data API comes in. You can actually use a cursor on it as it is able to expose 100 things at ago.
Essentially you’ll loop through it and at the end get average and post to an endpoint that is able to process the calculation for storage. Relevant links Data API - Bubble Docs

1 Like