Google App Engine is a PAAS offering from Google Cloud Platform, which enables you to build complex web solutions with significant ease without worrying too much about the scalability or infrastructure management. If you want to develop GAE applications using python and looking for a way to setup your development environment then this post is for you.
Installing GAE SDK
This is the easiest part, I am using the windows machine, so I can simply grab the installer from this link and then install it following the installation wizard like you have done million times already.
I am assuming since you are reading this post you must be a python developer and using the PyCharm as your IDE, but if you do not have PyCharm installed then you can install is from here.
PyCharm community edition does not come with GAE support out of the box, so you need to make changes here and there to make it work for you.
Make autocomplete work for GAE SDK in pycharm
Typically when you start building an application in python, you start with setting up a virtual environment, however when you are building GAE application, setting up virtual environment seems an overkill to me, since GAE in itself works like a container and ensures isolation. You can also not install GAE packages using pip since those get installed in your machine when you install SDK.
The most straight forward way to make GAE packages available to PyCharm is, by setting a hard symlink from GAE packages directory to python site_packages directory. To do this you need to open command prompt in elevated access mode (run as admin) and execute following commands:
mklink /J "C:\Python27\Lib\site-packages\google" "C:\Program Files (x86)\Google\google_appengine\google"
Make sure you change the paths correctly to reflect your machine specific paths.
Scaffolding basic GAE app
GAE application needs a few config files in order to get insights about your project and configure it during deployment in GAE. You can very well create these files manually following the GAE documentation, but I find this easier to generate a basic project structure using Google App Engine Launcher, which gets installed with GAE SDK.
Open the GAE Launcher, go to File->Create New Application, enter application name and create the application. Do not run the application from GAE launcher, we were only interested in the generated files.
Now go to the root directory of the generated application, change the name to whatever you want to name your project and open this directory in PyCharm.
In order to debug you GAE application, you need to perform following steps:
- Go to Run -> Edit Configurations
- Click on the + symbol to add new configuration and select Python
- Enter a name which you can remember like “Execute_GAE”
- In the
C:\Program Files (x86)\Google\google_appengine\dev_appserver.py, change the path to point to your machines GAE intallation path
- In the
Script parameterssection enter
--automatic_restart=no --max_module_instances="default:1" .
- In the
Working directorysection enter the path of the root directory of your project(the one with the app.yaml in it)
- Tick the share checkbox, it will create a idea configuration file in .idea directory
- Ensure that under
File -> Settings -> Build, Execution, Deployment -> Python Debuggeryou have
Attach to subprocess automatically while debuggingoption enabled.
Now you are good to start building GAE apps using PyCharm with debugging enabled.