You are previewing Programming Google App Engine with Python.
O'Reilly logo
Programming Google App Engine with Python

Book Description

This practical guide shows intermediate and advanced web and mobile app developers how to build highly scalable Python applications in the cloud with Google App Engine. The flagship of Google's Cloud Platform, App Engine hosts your app on infrastructure that grows automatically with your traffic, minimizing up-front costs and accommodating unexpected visitors. You’ll learn hands-on how to perform common development tasks with App Engine services and development tools, including deployment and maintenance.

App Engine's Python support includes a fast Python 2.7 interpreter, the standard library, and a WSGI-based runtime environment. Choose from many popular web application frameworks, including Django and Flask.

Table of Contents

  1. Preface
    1. A Brief History of App Engine
    2. Using This Book
    3. Conventions Used in This Book
    4. Using Code Samples
    5. Safari® Books Online
    6. How to Contact Us
    7. Acknowledgments
  2. 1. Introducing Google App Engine
    1. The Runtime Environment
    2. The Static File Servers
    3. Frontend Caches
    4. Cloud Datastore
      1. Entities and Properties
      2. Queries and Indexes
      3. Transactions
    5. The Services
    6. Google Accounts, OpenID, and OAuth
    7. Google Cloud Endpoints
    8. Task Queues and Cron Jobs
    9. Namespaces
    10. Developer Tools
    11. The Cloud Console
    12. Getting Started
  3. 2. Creating an Application
    1. Setting Up the Cloud SDK
      1. Installing Python
      2. Installing the Cloud SDK
      3. Authenticating with the Cloud SDK
      4. Installing the App Engine SDK
      5. Using the Launcher
    2. Developing the Application
      1. The User Preferences Pattern
      2. A Simple App
      3. Introducing the webapp Framework
        1. Templates, users, and Google Accounts
        2. Datastore models and web forms
      4. The Development Server Console
        1. Caching with memcache
        2. The Python Interactive Console
    3. Registering the Application
    4. Uploading the Application
      1. Using Two-Step Verification with the Launcher
    5. Testing the App
    6. Enabling Billing
  4. 3. Configuring an Application
    1. The App Engine Architecture
    2. Configuring a Python App
      1. Runtime Versions
    3. App IDs and Versions
    4. Multithreading
    5. Request Handlers
    6. Static Files and Resource Files
      1. MIME types
      2. Cache expiration
    7. Domain Names
    8. Google Apps
    9. Configuring Secure Connections
    10. Secure Connections with Custom Domains
    11. Authorization with Google Accounts
    12. Environment Variables
    13. Inbound Services
    14. Custom Error Responses
    15. Python Libraries
    16. Built-in Handlers
    17. Includes
  5. 4. Request Handlers and Instances
    1. The Runtime Environment
      1. The Sandbox
      2. Quotas and Limits
        1. Request limits
        2. Service limits
        3. Deployment limits
        4. Projects
        5. Versions
        6. Billable quotas
      3. The Python Runtime Environment
    2. The Request Handler Abstraction
    3. Introducing Instances
    4. Request Scheduling and Pending Latency
    5. Warm-up Requests
    6. Resident Instances
    7. Instance Classes and Utilization
    8. Instance Hours and Billing
    9. The Instances Console Panel
    10. Traffic Splitting
  6. 5. Using Modules
    1. An Example Layout
    2. Configuring Modules
    3. Manual and Basic Scaling
      1. Manual Scaling and Versions
    4. Start-up Requests
    5. Shut-down Hooks
    6. Background Threads
      1. Modules and the Development Server
    7. Deploying Modules
    8. Addressing Modules with URLs
      1. Calling Modules from Other Modules
      2. Module URLs and Secure Connections
      3. Module URLs and Custom Domains
    9. Dispatching Requests to Modules
    10. Starting and Stopping Modules
    11. Managing and Deleting Modules and Versions
    12. The Modules API
    13. An Always-On Example
  7. 6. Datastore Entities
    1. Entities, Keys, and Properties
    2. Introducing the Python Datastore API
    3. Property Values
      1. Strings, Text, and Bytes
      2. Unset Versus the Null Value
      3. Multivalued Properties
    4. Keys and Key Objects
    5. Using Entities
      1. Getting Entities Using Keys
      2. Inspecting Entity Objects
      3. Saving Entities
      4. Deleting Entities
    6. Allocating System IDs
    7. The Development Server and the Datastore
  8. 7. Datastore Queries
    1. Queries and Kinds
    2. Query Results and Keys
    3. The Query API
      1. The Query Class
        1. AND and OR clauses
      2. GQL
      3. Retrieving Results
      4. Keys-Only Queries
    4. Introducing Indexes
    5. Automatic Indexes and Simple Queries
      1. All Entities of a Kind
      2. One Equality Filter
      3. Greater-Than and Less-Than Filters
      4. One Sort Order
      5. Queries on Keys
      6. Kindless Queries
    6. Custom Indexes and Complex Queries
      1. Multiple Sort Orders
      2. Filters on Multiple Properties
      3. Multiple Equality Filters
    7. Not-Equal and IN Filters
    8. Unset and Nonindexed Properties
    9. Sort Orders and Value Types
    10. Queries and Multivalued Properties
      1. MVPs in Code
      2. MVPs and Equality Filters
      3. MVPs and Inequality Filters
      4. MVPs and Sort Orders
      5. Exploding Indexes
    11. Query Cursors
    12. Projection Queries
    13. Configuring Indexes
  9. 8. Datastore Transactions
    1. Entities and Entity Groups
      1. Keys, Paths, and Ancestors
      2. Ancestor Queries
    2. What Can Happen in a Transaction
      1. Transactional Reads
      2. Eventually Consistent Reads
    3. Transactions in Python
    4. How Entities Are Updated
    5. How Entities Are Read
    6. Batch Updates
    7. How Indexes Are Updated
    8. Cross-Group Transactions
  10. 9. Data Modeling with ndb
    1. Models and Properties
    2. Property Declarations
      1. Property Value Types
      2. Property Validation
      3. Nonindexed Properties
      4. Automatic Values
      5. Repeated Properties
      6. Structured Properties
      7. Computed Properties
      8. Models and Schema Migration
    3. Modeling Relationships
    4. Model Inheritance
    5. Queries and PolyModels
    6. Creating Your Own Property Classes
      1. Validating Property Values
      2. Marshaling Value Types
      3. Accepting Arguments
      4. Implementing Automatic Values
    7. Automatic Batching
    8. Automatic Caching
      1. Setting the cache policy for a kind
      2. More complex cache policies
      3. Ignoring caches per call
  11. 10. Datastore Administration
    1. Inspecting the Datastore
    2. Managing Indexes
    3. Accessing Metadata from the App
      1. Querying Statistics
      2. Querying Metadata
      3. Index Status and Queries
      4. Entity Group Versions
    4. Remote Controls
      1. Setting Up the Remote API
      2. Using the Remote Shell Tool
      3. Using the Remote API from a Script
  12. 11. Using Google Cloud SQL with App Engine
    1. Choosing a Cloud SQL Instance
    2. Installing MySQL Locally
    3. Installing the MySQLdb Library
    4. Creating a Cloud SQL Instance
    5. Connecting to an Instance from Your Computer
    6. Setting Up a Database
    7. Connecting to the Database from App Engine
    8. Backup and Restore
    9. Exporting and Importing Data
    10. The gcloud sql Commands
  13. 12. The Memory Cache
    1. Calling Memcache from Python
    2. Keys and Values
    3. Setting Values
      1. Setting Values that Expire
      2. Adding and Replacing Values
    4. Getting Values
    5. Deleting Values
      1. Locking a Deleted Key
    6. Atomic Increment and Decrement
    7. Compare and Set
    8. Batching Calls to Memcache
    9. Memcache Administration
      1. Cache Statistics
      2. Flushing the Memcache
  14. 13. Fetching URLs and Web Resources
    1. Fetching URLs
    2. Outgoing HTTP Requests
      1. The URL
      2. The HTTP Method and Payload
      3. Request Headers
    3. HTTP Over SSL (HTTPS)
    4. Request and Response Sizes
    5. Request Deadlines
    6. Handling Redirects
    7. Response Objects
  15. 14. Sending and Receiving Email Messages
    1. Sending Email Messages
      1. Sending Email from the Development Server
      2. Sender Addresses
      3. Recipients
      4. Attachments
      5. Sending Email
    2. Receiving Email Messages
  16. 15. Sending and Receiving Instant Messages with XMPP
    1. Inviting a User to Chat
    2. Sending Chat Messages
    3. Receiving Chat Messages
      1. Handling Commands over Chat
    4. Handling Error Messages
    5. Managing Presence
      1. Managing Subscriptions
      2. Managing Presence Updates
      3. Probing for Presence
  17. 16. Task Queues and Scheduled Tasks
    1. Configuring Task Queues
    2. Enqueuing a Task
    3. Task Parameters
      1. Payloads
      2. Task Names
      3. Countdowns and ETAs
    4. Push Queues
      1. Task Requests
      2. Processing Rates and Token Buckets
      3. Retrying Push Tasks
    5. Pull Queues
      1. Enqueuing Tasks to Pull Queues
      2. Leasing and Deleting Tasks
      3. Retrying Pull Queue Tasks
    6. Transactional Task Enqueueing
    7. Task Chaining
    8. Task Queue Administration
    9. Deferring Work
    10. Scheduled Tasks
      1. Configuring Scheduled Tasks
      2. Specifying Schedules
  18. 17. Optimizing Service Calls
    1. Calling Services Asynchronously
      1. Asynchronous Calls in Python
        1. Datastore
        2. Memcache
        3. Blobstore
        4. URL Fetch
        5. Using callbacks
    2. Visualizing Calls with AppStats
      1. Installing AppStats
      2. Using the AppStats Console
  19. 18. The Django Web Application Framework
    1. Using the Bundled Django Library
    2. Creating a Django Project
    3. Hooking It Up to App Engine
    4. Creating a Django App
    5. Using Django Templates
    6. Using ndb with Django
    7. Using WTForms with ndb
    8. Using a Newer Version of Django
    9. Using Django with Google Cloud SQL
  20. 19. Managing Request Logs
    1. Writing to the Log
    2. Viewing Recent Logs
    3. Downloading Logs
    4. Logs Retention
    5. Querying Logs from the App
    6. Flushing the Log Buffer
  21. 20. Deploying and Managing Applications
    1. Uploading an Application
    2. Using Versions
    3. Managing Service Configuration
    4. App Engine Settings
    5. Managing Developers
    6. Quotas and Billing
    7. Getting Help
  22. About the Author
  23. Copyright