Getting Started with PyCharm as Google App Engine IDE
In this Quick Start Guide we'll walk through creating a simple Google App Engine application with PyCharm.
Before You Start...
Make sure that the following software is downloaded and installed on your computer:
- Google App Engine for Python
- Python version 2.5.
Explore the requirements to the development environment here.
Important! Sign in to your Google account, and get the application id.
Creating Your First Google App Engine Application
Let's start with creating a simple Google App Engine application - the inevitable "Hello, world" - from scratch. Creating a new project is most easy: choose File | New Project on the main menu, or click Create New Project button in the Welcome screen.
On the first page, enter project name (here it is HW) and select its type — Google App Engine project:
Click OK. On the next page (2), let's choose the Python interpreter to work with, and enter the application id you have prudently obtained from Google App Engine. PyCharm automatically detects the directory where you have installed the Google App Engine SDK, and suggests location for the templates. In this small example, we'll do without Django support (which is intended for larger projects); so we'll leave the corresponding check box cleared.
Find detailed description of the procedure here. After clicking OK, PyCharm suggests you to specify how you want your new project to be opened: in a new window, or added to some previously opened project.
Finally, PyCharm produces the following structure, which you can explore in the Project tool window:
Besides that, PyCharm generates two files:
app.yamlwhich defines the Python runtime environment, API version, and a reference to the handler, which will be executed
- the default request handler
If you look into
main.py, you will see that "Hello world!" is already there. However, this is far too
simple... let's create a different handler. Press Alt+InsertCtrl N, and choose Python File in the pop-up frame.
Next, specify file name (let it be
hw.py file opens in the editor.Let's create a request handler. Enter the following code:
from google.appengine.ext import webapp from google.appengine.ext.webapp import util class HwHandler(webapp.RequestHandler): def get(self): self.response.out.write('Hi there!') def main(): application = webapp.WSGIApplication([('/', HwHandler)], debug=True) util.run_wsgi_app(application) if __name__ == '__main__': main()
It is recommended that you type this code manually. Thus you will try hands-on the various coding assistance features: syntax and error highlighting, automatic indentation, and code completion. For example, as you type, press Ctrl+Space⌃Space first in the import statements, and then in the class definition (3):
app.yaml (4): specify the script you want to be run. In our case, this is
Note that code completion is available here.
after colon, and select the desired script from the suggestion list:
Running Application Locally
Our simple application is ready. Before uploading it to your App Engine space, let's try to launch it locally. For this purpose, PyCharm provides run/debug configuration. Have a closer look at it: on the main toolbar, click the run/debug configuration selector (which now shows HW), and choose Edit Configuration:
The Run/Debug Configurations dialog box shows the configuration, which PyCharm has generated automatically:
All you have to do here, is to select the check box Run browser - thus your application will be automatically opened in a page with the specified IP address. Apply changes and close the dialog.
Next, press Shift+F10Shift F10, or click on the main toolbar - and observe your application's output in browser.
Uploading Your Application
We are now sure that the application works properly, and can upload it to appspot. This is how it's done:
On the Tools menu, point to Google App Engine node, and choose Upload App Engine app:
In the App Engine Account dialog box, sign in to your account.
appcfg.py, and displays output in
appcfg.py tab of the Run tool window:
Great! The application is successfully uploaded. Visit your Google Accout, and see it running:
This brief tutorial is over. You have successfully created and launched a simple Google App Engine application - congrats!