Skip to content Skip to sidebar Skip to footer

Creating An Api To Execute A Python Script

I have a python script app.py in my local server (path=Users/soubhik.b/Desktop) that generates a report and mails it to certain receivers. Instead of scheduling this script on my l

Solution 1:

A good way to do this would be to put the script into a function, then import that function in your Flask API file and run it using that. For hosting on a web server you can use Python Anywhere if you are a beginner else heroku is also a good option.

Solution 2:

If you are tying to achieve something using Python-Flask API than you can have a close look at this documentations and proceed further https://www.flaskapi.org/, http://flask.pocoo.org/docs/1.0/api/

Apart from these here are few basic examples and references you can refer for a quickstart :

1-https://programminghistorian.org/en/lessons/creating-apis-with-python-and-flask

2- https://flask-restful.readthedocs.io/en/latest/

3- https://realpython.com/flask-connexion-rest-api/

Solution 3:

You could do something like this

from flask import Flask
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

classExecuteScript:
  defprintScript:
    return"Hello World"

api.add_resource(ExecuteScript, '/printScript')

if __name__ == '__main__':
    app.run(debug=True)

Post a Comment for "Creating An Api To Execute A Python Script"