Forum Academy Marketplace Showcase Pricing Features

Can bubble run python scripts?

I’m not sure if Bubble’s compiler minifies code that is used within workflows. It certainly minifies all plugin code, but it’s possible that it doesn’t ‘see’ the code used in the Run Javascript action.

Minification doesn’t offer real security for your code - it’s there to reduce the file sizes - but it does make it really hard to read. For example:

var profit = 1000;
var scaler = 0.3;
function secretCalc(input, multiplier) {
    return (input *100) / multiplier;
}
console.log(secretCalc(profit, scaler);

Becomes:

var n=1e3;var r=.3;function e(n,r){return n*100/r}console.log(e(n,r));

And this code will be sat within a sea of other a, b and c variables and functions. From personal experience I can tell you it’s between really hard --> impossible to work out what’s going on. So once you’ve written your code you can use a tool like this to minify it.

Alternatively you can run your code server side (Backend Workflows in Bubble) and then it will never touch the client. Toolbox has a server side action too - Server Script - you can see how it works here. You’ll need to save the return value to the database in order to access it back on the client.

1 Like

Thanks for all the info shared on this thread, its super helpful. I’m curious if you think it’d be possible to take an image uploaded to a bubble app, pass it to pythonanywhere to do some image transformations/detections using openCV, and then return the transformed image back to bubble?

Hey Ken, I’m really curious - how are you actually storing/attaching the processed csv’s onto a bubble thing from python? Do you have to base64 encode first? In my case I’m trying to attach a .pickle file onto a bubble thing and am really scratching my head on how to proceed.

Actually, never mind :slight_smile: I just figured it out!!

Python side it looks like

from flask import Flask, json, jsonify, make_response, request
from werkzeug.wrappers import Response
from werkzeug.wsgi import FileWrapper
import io
import pandas as pd

@app.route('/process-zipfile', methods=['GET'])
def call13():
    zip_url = request.form.get('zip_url')
    ## CREATE PANDAS DATAFRAME ##

    df = df[columns]
    buffer = io.BytesIO()
    df.to_pickle(buffer)
    buffer.seek(0)
    file_wrapper = FileWrapper(buffer)
    headers = {
        'Content-Disposition': 'attachment; filename="{}"'.format("df_cleaned.pkl")
    }
    response = Response(file_wrapper,
                        mimetype='application/octet-stream',
                        direct_passthrough=True,
                        headers=headers)
    return response

And then you would call that endpoint / catch the response using the Bubble API connector (as a GET request that saves a FILE)

Hey @gevestobs, I am currently trying to deploy a simple python selenium webscraping script as a scheduled task on PythonAnywhere. I have been struggling to make it work for some time. The script functions as a quick check that verifies a new user’s social media following when they register on our bubble site. I want the script to run as soon as they register. However, when trying to connect the scheduled task to our website using the API Connector, I cannot see the parameter I have specified in the script. I just see general information that PythonAnwyhere provides such as “Expiry Date”, “Time Scheduled”, etc.

Apologies if it’s too specific but if you are aware of what steps to take, I would really appreciate some help!

I need to use Python scripts I’ve written to gather specific information and then take that data and create and update database entries. How hard or easy is it to update Bubble’s database after you run a Python script?

Here’s a Python snippet I wrote for retrieving database data. I haven’t yet written anything to directly modify the Bubble DB via API/Python but that of course is one option available to you. Another option is to create a webhook endpoint/workfllow in Bubble that you call via your Python script that will then do the updating for you.

1 Like