This page shows you how to configure, deploy, and send requests to a sample API by using Cloud Endpoints Frameworks for Python. Endpoints Frameworks for Python is integrated with the App Engine standard Python 2.7 runtime environment. Endpoints Frameworks consists of tools, libraries, and capabilities that let you generate APIs and client libraries from an App Engine application.
Objectives
Use the following high-level task list as you work through the tutorial. All tasks are required to successfully send requests to the API.
- Set up a Google Cloud project. See Before you begin.
- Install required software and create an App Engine application. See Installing and configuring required software.
- Download the sample code. See Getting the sample code.
- Generate an OpenAPI document. See Configuring Endpoints.
- Deploy the Endpoints configuration to create an Endpoints service. See Deploying the Endpoints configuration.
- Run the sample on your computer. See Running the sample locally.
- Create a backend to serve the API and deploy the API. See Deploying the API backend.
- Send a request to the API. See Sending a request to the API.
- Track API activity. See Tracking API activity.
- Avoid incurring charges to your Google Cloud account. See Clean up.
Costs
In this document, you use the following billable components of Google Cloud:
To generate a cost estimate based on your projected usage,
use the pricing calculator.
When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, see Clean up.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
- Make a note of the Google Cloud project ID because it is needed later.
Installing and configuring required software
- Follow the instructions in
Installing Google Cloud CLI
for Python to get your App Engine standard development
environment set up. Make sure you install the
app-engine-pythonandapp-engine-python-extrasgcloudcomponents. - Run the following commands:
-
Update the gcloud CLI.
gcloud components update
-
Make sure that the Google Cloud CLI (
gcloud) is authorized to access your data and services on Google Cloud:gcloud auth login
- In the new browser tab that opens, choose an account.
-
Set the default project to your project ID.
gcloud config set project [YOUR_PROJECT_ID]
Replace
[YOUR_PROJECT_ID]with your Google Cloud project ID. If you have other Google Cloud projects, and you want to usegcloudto manage them, see Managing gcloud CLI configurations.
-
Update the gcloud CLI.
-
You need an application to send requests to the sample API.
- Linux and macOS users: This tutorial provides an example of using
curl, which typically comes pre-installed on your operating system. If you don't havecurl, you can download it from thecurlReleases and downloads page. - Windows users: This tutorial provides an example using
Invoke-WebRequest, which is supported in PowerShell 3.0 and later.
- Linux and macOS users: This tutorial provides an example of using
- Make sure your Python development environment includes pip.
- Be sure you can compile C extensions for Python.
- Windows: Microsoft Visual C++ 9.0 or greater is required. You can download the Microsoft Visual C++ Compiler for Python 2.7 from the Microsoft Download Center .
- Other operating systems: Depending on your operating system, you may need to
install compiler tools (sometimes in a package called
build-essential) or the Python development headers (sometimes in a package calledpython-dev).
-
For Linux, set the
ENDPOINTS_GAE_SDKenvironment variable to the path of your App Engine SDK folder:[Path-to-Google-Cloud-SDK]/platform/google_appengine.Replace
[Path-to-Google-Cloud-SDK]with the output of the following command:gcloud info --format="value(installation.sdk_root)"
- Create an App Engine application:
- Select the region where you want to create your App Engine
application. Run the following command to get a list of regions:
gcloud app regions list
- Create an App Engine application using the following command.
Replace
[YOUR_PROJECT_ID]with your Google Cloud project ID and[YOUR_REGION]with the region that you want the App Engine application created in.gcloud app create \ --project=[YOUR_PROJECT_ID] \ --region=[YOUR_REGION]
For example:
gcloud app create --project=example-project-12345 --region=us-central
- Select the region where you want to create your App Engine
application. Run the following command to get a list of regions:
Getting the sample code
To clone the sample API from GitHub:
Clone the sample repository to your local machine:
git clone https://github.com/GoogleCloudPlatform/python-docs-samplesChange to the directory containing the sample code: