AppEngine (AppInventor TinyWebDb application) access from a python local application

161 views
Skip to first unread message

Christian Feniou

unread,
Oct 28, 2016, 12:29:23 PM10/28/16
to Google App Engine
Hello,

I built an application with App Inventor which uses AppEngine application. It work well with my Androïd application.
Then, for certain usages, I'd like to access the data from a PC or other machine, thru a Python application.

Is anyone to tell me the way to do this access ? For example, here is a test AppEngine application : https://exe-chords.appspot.com/

If you try to access the above address from a browser, you'l get datas sent by AppEngine to an Index.html file like this :

(see the jointed file)

When I do the access from the AppInventor application, I receive the data directly into the application.

How to do this direct access from a Python application ?

Thank you per advance for any answer !

index.html

George (Cloud Platform Support)

unread,
Oct 28, 2016, 5:25:23 PM10/28/16
to Google App Engine

Hello Christian,

Thank you for posting your issue here!


App Engine applications are meant to be accessed from a browser. The app itself might be written in Python. You can find such an example here.

If you want to access your data, such that contained in form fields on a web page, from a python program running on a PC, you may put to good use some of the many examples and tutorials on the web.

Let us know if this addresses your concerns, and if you need more information on the App Engine.


I hope this helps. Cheers!

Christian Feniou

unread,
Oct 29, 2016, 3:55:34 AM10/29/16
to Google App Engine
Hello George,

Thank you so much for your answer. I'll have a look on the addresses you gave me. I hope I'll found the call back example I'm looking for !!
I'll inform you soon for the result of these "investigations"...

Sorry for my low quality English language but, as you certainly understand I'm French...

Have a good weekend,

Best regards

Christian Feniou

unread,
Oct 29, 2016, 12:51:33 PM10/29/16
to Google App Engine
Bonsoir George,

Unfortunately, there is not the answer I'm looking for in these links ! There are many documents and examples to build and deploy a server application but the sample I search is a "client" python application.

In the server source code it's a difference between access from Web or access from application :

def WriteToPhone(handler,tag,value):
 
    handler.response.headers['Content-Type'] = 'application/jsonrequest'
    json.dump(["VALUE", tag, value], handler.response.out)

def WriteToWeb(handler, tag,value):
    entries = db.GqlQuery("SELECT * FROM StoredData ORDER BY date desc")
    template_values={"result":  value,"entryList":entries} 
    path = os.path.join(os.path.dirname(__file__),'index.html')
    handler.response.out.write(template.render(path,template_values))

My main problem is how to pass the "questions" with the right parameters from the local python application to the server...

I seen a module named "google.appengine.api.datastore"  looking as the module I need... But I don't know how to implement it.

Thanks a lot...

Anastasios Hatzis

unread,
Oct 29, 2016, 7:01:39 PM10/29/16
to Google App Engine
Christian,

maybe you want your local Python client to directly interact with the datastore used by the server app?
In this case, you would need the Cloud Datastore client library for Python (and Tutorial here). However, I would like to take a few aspects into consideration (since I don't know what you actually want to achieve).

I haven't looked into App Inventor, but from your server source code sample I assume, that the server is running in Google App Engine (Python). It is able to handle requests from either a client app on a smartphone (by using JSON) or from a Web-browser (rendering and returning an HTML page). The sample also shows that data is stored in Google Cloud Datastore. For doing this inside a server app on GAE (Python), you have two libraries available to access the Datastore API easily and directly from the GAE app: the old `db` library (as in your sample), or the new `ndb` library. I don't think you can use these libs outside of GAE.

If you want to implement a local Python client in this setup you can pick between two approaches:
(1) Access the server app like your mobile app through some kind of HTTP REST API. Advantage: business logic built into your server app is always applied and the server can safeguard your data in many ways - whatever client and user is interacting with the server app. Consider the potential risk that a client is malicious or its code has been modified. Disadvantage: this approach might require some more efforts in designing the different layers (i.e. separation of concerns).

(2) Directly access the data, with no server that would impose safeguard measures. In this case, your local Python client does not interact with the web-app on GAE, but directly with Google Cloud Datastore API. Advantage: you can build a query directly into the local Python client, no need to modify the server app. Disadvantage: if you allow the Python client to write directly to the datastore, you can mess up the data in many ways (especially if the client is not an internal tool of yours, but also used by many other users).

So, if you want a local Python client as internal admin tool, preferably read-only datastore access, you should be fine with the second approach. In that case, the Cloud Datastore client library for Python is your choice. For everything else, I recommend the first approach, so your Python client interacts with the server, just as your mobile app does. In this case, you need to learn how your Python client can send HTTP requests to your server app and how to process the response. And of course you would need to learn how to implement any missing API / feature on your server app.

I hope this was helpful for you.

Anastasios

Christian Feniou

unread,
Oct 30, 2016, 9:36:46 AM10/30/16
to Google App Engine
Hello Anastasios,

I thank you very much for this detailed answer. I think the N° 1 solution is the one I will use. I do not want any database or service modification it's why I'd like build a local Python App taking exactly the same mechanism than the Androïd app to access the datas...

Thank you again. Have good Sunday.

Best regards,

Christian.

George (Cloud Platform Support)

unread,
Oct 31, 2016, 12:26:34 PM10/31/16
to Google App Engine

Hello Christian,

The link provided in my initial reply referred erroneously to creating an app in the cloud, not to a Python client; I correct it here. For your N° 1 solution, you may consider the App Engine Python API. A tutorial is also offered.

Vous êtes le bienvenu si écrire en français facilite la communication.
Reply all
Reply to author
Forward
0 new messages