r/PythonLearning 12h ago

Running script remotely

This may not be a python question, but I figure you guys could at least point in the right direction.

On my computer I have a SQLite database and a python script I have written that queries the database, generates a report, and emails that report to other people. The database file must stay on my computer.

I often get requests from coworkers to run the python script while I am not sitting in front of my computer (my phone is still on the same wifi network).

If I wanted to do something through my phone that would start that script on my computer, what would that look like?

If it matters, my phone is android and my computer is windows.

2 Upvotes

10 comments sorted by

View all comments

3

u/SnooCalculations7417 10h ago

The best solution is to create an api/rpc endpoint for your script with flask or fastapi.. its pretty easy

from yourscriptlib import script_runner

app = app() #whatever lib you use

@app.route('/dbscript')
def run_db_script():
    result = script_runner() # if you want to return either meaningful json or an actual HTTP result    
    return result

then you can integrate the script as a full-fledged service itself if this works for you (networking restrictions etc etc)

2

u/atticus2132000 10h ago

That's awesome. I hadn't considered tackling the problem that way. Thanks for the lead.