Network Behaviors with Glitch Servers and Python
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
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.
I just added all the gs table functions as helpers (though I haven't tested them yet)
Google's response times are problematically slow, so this is perfect timing! I'll be digging into this very soon, thanks!
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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.
Good tip, thanks! If it's nice and quick with the responses it would be well worth the fee.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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!
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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
GAMESALAD DEV FOR HIRE! - www.gingagaming.com
@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.
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?
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
@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.
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.
@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.
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?
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
I have zero familiarity with python but can vaguely muddle my way ineffectively around things in Javascript, so Javascript gets my vote.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
@Armelline yup: so for my sample project: https://gamesalad-tables-fastapi.glitch.me/
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!
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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.
@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
@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.