DEV Community

Cover image for How to Convert your Python Scripts into Hosted Applications in Minutes
Derrick Sherrill for WayScript

Posted on

How to Convert your Python Scripts into Hosted Applications in Minutes

Introduction

In today’s tutorial we’ll look at how versatile the WayScript platform is, along with showing you how easy it is to execute a local Python script in a WayScript program. Specifically, we’ll be using a Python script with a command line function and converting it into a program that uses a Form Trigger module. Keep reading to learn more!

Building our Script

To begin, we have a local Python script with a command line argument that passes a website – in this case, wayscript.com – to the script.

Tutorial step #1

Now, we’ll convert this local script into a WayScript program. This example uses a Form Trigger module that collects information from a hosted URL. You can customize the title, description, and more for the module in the left screen toolbar. Once activated, the form can be viewed in a new tab. Anything that is submitted in the form then gets stored as a WayScript input that’ll be used later.

Next, we’ll add a Python module to host the Python script we’ve already created. Copy the script and paste it in the code editor. The pasted code looks like this.

Tutorial step #1

In order to get the code to work in WayScript, we’ll simply delete the highlighted code and tab the rest back over. Now, instead of using a command-line argument with the code

url = sys.argv[i]
we’ll drag the input that was created from our earlier form submission after the “url =” portion of the code. With that, the local Python script is now hosted in WayScript. Now that the local script is hosted on the WayScript platform, there are many more options you could add to the program. For example, if you wanted to return a status code 200 back to the user after they submitted a form, you could do it by adding this line of code to create a WayScript variable:
variables[‘string’] = status

Then, by adding an HTTP Response module and dragging the newly created variable into the “Response Content” box, it would return a status code 200.

There are plenty of other modules you could also use in this program. This is only one example of WayScript’s unique versatility. Start creating your own programs today and see just how much you can do!

Conclusion

Questions about this script or anything else? Join our discord. We're always around to help. If you want to work the full script template, just find it here.

Top comments (0)