I'm building a web app in AppEngine that uses the Spotify API and I can't figure out the best way to store an access/refresh token locally using Python and AppEngine. I've looked into AppEngine's Memcache which just seems like overkill, and Javascript's localStorage which just starts to get complicated since I'd have to transfer data back and forth between Python and Javascript constantly.
I'm assuming that you want to save the access token from Spotify. I like to use Datastore to save anything shared between my instances, but I not sure that is the best way to do that, but probably it is a simple and fast way.
So, to solve this issue I'll probably to create an entity in Datastore.
Another alternative could be Firestore
Related
I have JS running and essentially getting user entries from my HTML session storage and pushing these to a DB. I also need to use a HTTP request to pass a json object containing the entries to a python file hosted somewhere else.
Does anyone have any idea of documentation I could look at, or perhaps how to get JSON objects from JS to Python.
My client does not want me to grab the variables directly from the DB.
You have to create some sort of communication channel between the javascript and python code. This could be anything, SOAP, HTTP, RPC, any number of and flavor of message queue.
If nothing like that is in place, it's quite the long way around. A complex application might warrant you doing this, think micro services communicating across some sort of service bus. It's a sound strategy and perhaps that's why your client is asking for it.
You already have Firebase, though! Firebase is a real-time database that already has many of the characteristics of a queue. The simplest and most idiomatic thing to do would be to let the python code be notified of changes by Firebase: Firebase as service bus is a nice strategy too!
I am writing a micro-service that will have to share database owned by a different micro-service.
I understand that from a micro-services architecture perspective, this is not a good design. Hence, I decided to separate out the database access as another micro-service, whose only task it to manage access to db.
I need pointers on how I may write such an app using Python which exposes API for read/write to a database?
I realize this is not a design perspective answer.
Did you have a chance to take a look at sandman, a Python library that can generate a REST API over a database?
My friend has a website built using Pyramid framework and using MongoDB to store data. If I want to build an iPhone app, how do I access the data from that database?
I know Obj-C and have built simple, iOS apps, but none of them used non-local data. I've googled but no good result returned. I just don't know where to start. Any good tutorial or sample code on the related issue would be appreciated!!
As far as best practices go, you would not want to be accessing MongoDB (or any database) directly over the internet without appropriate security considerations.
The most straightforward option from iOS would probably be either add a RESTful interface to your own application, or use a third party hosted solution that provides an API. In either case I would recommend using https in addition to authentication, as the MongoDB wire protocol is not currently encrypted.
For iOS I would consider using the RestKit framework as a handy helper. It includes reasonable documentation and examples to get you started.
I'm in the middle of trying to create a django website to access data in a MySQL database. The intenion is to also create a UI in Dojo (javascript). Also I would like the django backend to also provide webservices (RPC for python functions) to allow access to the MySQL database remotely. So for example, if someone wants to use Perl scripts to access the database (and possible other additional functionality like calculations based off of data in the database) they can do so in their native language (Perl).
Now ideally, the web services API is the same for javascript as well as another remote service that wants to access these services. I've found that JSON-RPC is a good way to go for this, as there is typically built in support for this in javascript in addition to the numerous additional benefits. Also a lot of people seem to be preferring SOAP to JSON.
I've seen several ways to do this:
1) Create a unique URI for each function that you would like to access:
https://code.djangoproject.com/wiki/JSONRPCServerMiddleware
2) Create one point of access, and pass the method name in the JSON package. In this particular example an SMD is automatically generated.
https://code.djangoproject.com/wiki/Jsonrpc
The issue with (1) is that if there are many functions to be accessed, then there will be many URI's that will be used. This does not seem like an elegant solution. The issue with (2) is that I need to compare functions against a list of all functions. Again this is not an elegant solution either.
Is there no way that we can take the advantages of (1) and (2) to create an interface such that:
- Only one URI is used as a point of access
- Functions are called directly (without having to be compared against a list of functions)
Any help with this will be really appreciated. Thanks!
what about using REST API?
One possibility to do the comparisons would be to use a dict like so:
def func1(someparams):
#do something
return True
def func2(sameparams):
#do something else
return True
{'func1': func1,
'func2': func2}
Then when you get the API call, you look it up in the dict and call from there, any function not in the dict would get the 404 handler.
It sounds like what you really want is a RPC server of some kind (SOAP, say, using soaplib) that is written in python and uses your application's data model, and what ever other APIs you have constructed to handle the business logic.
So I might implement the web service with soaplib, and have it call into the datamodel and other python modules as needed. People wanting to access your web application's data would use the SOAP service, but the web application would use the underlying datamodel + apis (for speed, your web app could use the SOAP service too, but it would be slower).
I'm writing a simple app with AppEngine, using Python. After a successful insert by a user and redirect, I'd like to display a flash confirmation message on the next page.
What's the best way to keep state between one request and the next? Or is this not possible because AppEngine is distributed? I guess, the underlying question is whether AppEngine provides a persistent session object.
Thanks
Hannes
No session support is included in App Engine itself, but you can add your own session support.
GAE Utilities is one library made specifically for this; a more heavyweight alternative is to use django sessions through App Engine Patch.
The ways to reliable keep state between requests are memcache, the datastore or through the user (cookies or post/get).
You can use the runtime cache too, but this is very unreliable as you don't know if a request will end up in the same runtime or the runtime can drop it's entire cache if it feels like it.
I really wouldn't use the runtime cache except for very specific situations, for example I use it to cache the serialization of objects to json as that is pretty slow and if the caching is gone I can regenerate the result easily.