Network Behaviors with Glitch Servers and Python

adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,172
edited August 2020 in GameSalad Kitchen

It's the weekend and I decided to take a break from work to have some fun with network behaviors, learn me some python, and try out glitch.

Glitch is a system that lets you program server apps online and instantly have a running server to try them out on.

The projects are public by default, so you can take a glitch, 'remix' it, and make it your own.

I setup up a basic project to parse the GameSalad send table to network behavior.

What's awesome is Glitch's free tier allow for 4,000 request per hour, which is perfect for development or an app without too much traffic.

You can pay glitch $10/month to increase the limits on 5 of your projects, so as your project grows, you have a quick option to scale.

And because the apps are running in node / python, you can move the apps to your own server when you're done. I did this one in python because that's what I wanted to learn and possibly build an EDU unit around, but if you prefer javascript (like me), let me know. I can always port the google docs gist into another glitch project.

I'm still trying to figure out how databases work, but in theory you could have glitch access a third party cloud database and APIs like AirTable or Firebase with libraries like

https://airtable-python-wrapper.readthedocs.io/en/master/

https://pypi.org/project/python-firebase/

The other good thing is that because glitches are public by default, we can all help each other out just by sharing links and trying stuff live! They have an .env file mechanism to set up private environment variables to project API keys and you can make glitch projects run in private, so your code is not exposed when you're live.

Anyway, I hope this helps people out! I'm gonna be heads down in other code early next week, so I might be slow to get back to your questions, hopefully you can help each other out!

Cheers!

Comments

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,172

    Also, if you have any ideas on what kind of sample projects you'd like to see for specific task, let us all know. I'm sure there are a few coders around there that could whip up some sample code.

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,172

    I just added all the gs table functions as helpers (though I haven't tested them yet)

  • ArmellineArmelline Member, PRO Posts: 5,365
    edited August 2020

    Google's response times are problematically slow, so this is perfect timing! I'll be digging into this very soon, thanks!

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,172

    So once you're ready for "production" you'll probably want to pay for the service. The system hibernates the app when it's not used in a while, so the first response after hibernate is rather slow. Paying the monthly fee will allow you to designate an app as always on.

  • ArmellineArmelline Member, PRO Posts: 5,365

    Good tip, thanks! If it's nice and quick with the responses it would be well worth the fee.

  • ArmellineArmelline Member, PRO Posts: 5,365
    edited August 2020

    I'm struggling to wrap my head around this one. My understanding was that it runs the server for you, that you can run it yourself if you want but you don't need to. I cloned your project so I could (later) make the changes I'll need to, but I can't even get it to receive a table successfully. What should I be putting in the send behaviour? I'm assuming I should be using the live app URL, but I'm not at all clear exactly how... Would it be possible for you to provide some very brief instructions like you did for Google Sheets? Once I've got a super-simply test project sending and receiving I'm confident I'll be able to get it going from there, but I'm hitting a wall at first step right now. Thanks!

  • gingagaminggingagaming FREELANCE GS DEV Member Posts: 1,685

    Im watching this very closely as I am making a big change from Appformitive to my own server these next two weeks. I was about to flip it to google sheets with your already documented help but if this is the way to go, Ill migrate to this. So I am +1 to any sort of doc or tutorial to do this. This is quite a big thing for many devs. So if we can have some guidance, it will go a long way @adent42

    Thank you in advance

  • solnikasolnika Member Posts: 132

    @adent42 @Armelline @gingagaming


    I would like to suggest you all checking the google cloud function and firestore option.


    If I manged to make it work I'm sure everybody can.

  • ArmellineArmelline Member, PRO Posts: 5,365
    edited August 2020


    Google Sheets seem easy and flexible but they're just too slow to be viable. It can be 5+ seconds before a table is properly received by Google, so I found people would close the app before it finished and those updates would be lost. Very unfortunate as Sheets would be a great place for us to have the data for reference from our end.


    @solnika By Google cloud function do you mean with this, or the other thread about sheets. Which is the Firestore option?

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,172

    @solnika yup, i'm all for Google Cloud Functions + Firebase Or Lambda + DynamoDB.

    This can help you work on and debug your logic live at least (it's basically running your app in a small container environment).

    So if you develop by separating core logic and request logics, you port these functions into a cloud function/lambda and be off to the races.

    I will keep an eye out for something that more directly simulates the real serverless options though, that way the port is more seamless.


    @Armelline The functions there's less in the way of instructions here since it's a very basic system. I've only testing Send Table and not Get Table. PM me a link to your glitch, if it's public, and I can try it out and see what's up.

    If I have some time, I'll do a video this weekend to document it.

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,172
    edited August 2020

    Also as a mini poll, would people rather program in python or javascript? I did this one in python because i wanted to learn it better and because we will likely be doing python for school units in the future.

    BUT if more people here want javascript, I'm actually a bit faster at it and glitch's first choice is to run as a node.js server and not a python server.

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,172

    @Armelline so I'm not 100% sure, but i didn't test the gstables.table_search function yet. So you may be getting an error if that code is bad. You can remove the lines:

     hello_row_index = gstables.table_search(table, "hello", "row", 1, 1, 4, "exact")

     print("Hello Found On: ", hello_row_index)

    And see if it works better.

  • ArmellineArmelline Member, PRO Posts: 5,365

    No change, but I really don't think I'm trying to do it properly. I think they problem is my lack of understanding rather than a problem with the code.

    With Google I'd use this with a send table behaviour: "https://script.google.com/macros/s/zbSIltrtrtrtrtrtrtrtrrtryZCoNNwQGTjqpBEk/exec?tableId=id800171&userID=88888888"

    I'm not even sure what address to use or how to format it for this, or if there's anything I need to do on Glitch first, other than clone the project. I presume I'll be using "https://project-name.glitch.me" as the base?

  • ArmellineArmelline Member, PRO Posts: 5,365

    I have zero familiarity with python but can vaguely muddle my way ineffectively around things in Javascript, so Javascript gets my vote.

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,172
  • ArmellineArmelline Member, PRO Posts: 5,365

    And nothing is required on the Glitch side after cloning the project? If my problem isn't with the send behaviour it must be something I didn't do on the Glitch side. Thanks!

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,172

    Looks like my code was bad (I added a bunch of function i hadn’t tested yet and some were causing compile error. Working better now.

  • solnikasolnika Member Posts: 132
    edited August 2020

    @Armelline I'm not sure I understand the question correctly.

    The google cloud function can be used to run little scripts that get triggered by https request.

    Firestore is firebase database .


    You can use cloud function to store and pull data from firestore and to do all kind of actions.

    Is that what you are asking?


    @adent42 thanks I will try to play with it, I do remember checking it out a few years ago but I gave up cuz it was to hard for me.


    P.S

    prefer node.js as well

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,172

    @solnika Armelline's question was about glitch vs using google doc's web request functionality, not the google cloud services.

    For Google Cloud, if you're doing python, you can use the gstable.py file to parse the incoming request. The big difference is where the query params/arguments come in from. Looking at some google cloud functions sample code you just need to grab them from request.args instead of from the function params.

    Looks like google cloud functions uses flask for python, so I could probably build a version that works on both glitch and google cloud functions later. Thanks for making me think about it, might be a project for next weekend if you don't get to it first.

Sign In or Register to comment.