How to run a Flask app under Google App Engine locally? - google-app-engine

I'm using Python 3.x under GAE. Google now recommends avoiding dev_appserver.py and instead to call python main.py.
When I do this my local code modifies my GAE server datastore rather than a local version.
How do I run my Flask app locally? I want to do this so that index.yaml is automatically created and provide a testing environment away from test and production servers.
The reason why my code is not using a local datastore is because I'm calling
from google.cloud import datastore
DATASTORE_CLIENT = datastore.Client()
and this is auto-authenticating to my Google hosted database. How do I have locally run code use a local datastore and server-run code use my server-based datastore?

Related

Local or development Google Cloud Firestore database with App Engine

In my previous App Engine projects I used the Cloud Datastore, and during development I could debug my app on the local server and it would use a local database, stored in a file I could wipe out if I wanted to start from scratch.
With Cloud Firestore, even when I'm running locally it's talking to my real cloud database. Is there still a local option? Note that I'm not talking about client-side persistence, I'm talking about a mock development DB.
Google recommends setting up multiple projects if you want dev/staging/production, and I'm guessing that's the answer, but I'd like to know before adjusting my workflow.
I think (now only a few months later) that this is supported. When I run my app, using dev_appserver.py, I see a message
INFO 2019-02-14 00:08:56,030 admin_server.py:150] Starting admin server at: http://localhost:8000
Going to that URL shows me all the instances I have been seeing. These seem to persist even when the dev_appserver is restarted. Reading this and other posts I was convinced that my development was using my actual cloud database, but going to https://console.firebase.google.com/project/myproject was showing completely different content.
Just to be sure (because google is google and everything is named the same) I'm using an appengine app and a gcloud project, storing things to Firestore using ndb.Models...
Oh, but careful. My app I was also using the cloudstorage (blobstore?) and even though the localhost:8000 showed these, THESE WERE THE REMOTE INSTANCES.
There is a local emulator for Firestore when using the Firebase CLI:
https://firebase.google.com/docs/rules/emulator-setup

Is an App Engine instance required for accessing Datastore?

Do I need to deploy an App (even a dummy one) on the App Engine in order to use the Datastore service using the google-cloud-datastore Java API from a client such as a Compute Engine running in the google cloud?
No, you don't need to deploy an AppEngine app to access the Google Cloud Datastore. You just need to create a project from the Console and you can connect to the Datastore in the project from anywhere using the google-cloud-datasource API.

Upload Local Datastore with Application

I'm using the Eclipse Plugin for App Engine, and I have my application running fine locally (able to read/write to the local Cloud Datastore).
However when I deployed to App Engine, the server copy does not seem to have any Cloud Datastore information. Do I need to upload this separately, and if so how do I do this?

Using Google App Engine services outside of uploaded application

I am looking to use Google Cloud Storage services outside of launching a google app engine application. My application is designed for running on a hosted server of our own, and I would like to still use the cloud storage service.
I've written a dev app that did this, and ran it with dev_appserver.py in the python GAE framework. It seems the dev_appserver.py is necessary as it fills in how to perform the RPC functions the cloud storage provides.
Is there a way to easily use google cloud storage service without the rest of it?
There is gsutil command line tool:
https://developers.google.com/storage/docs/gsutil
There is an xml/json restful service all at:
https://developers.google.com/storage/index
You'll need to enable the google cloud storage on the google console at:
https://code.google.com/apis/console/ and get the necessary api keys.

Connecting to a datastore in GAE when developing in eclipse

I don't get something about the use of datastore in a gae app.
I can see after deploying to GAE your app would be using their datastore in the cloud. But when you are still developing the app in eclipse on your local machine, how is it talking to GAE's datastore?
A local simulation of the appengine datastore is created and used - you're not talking to the actual GAE datastore.
You can view your local datastore by going to :
http://localhost:8888/_ah/admin
while your application is running locally.
(using the correct port for your application)

Resources