python-docs-samples

(★ 8,125)

Code samples used on cloud.google.com

File Explorer

Showing a partial file list — download the zip above to see everything.

  • .gitignore
  • .repo-metadata.json
  • .trampolinerc
  • .trampolinerc_tmpl
  • AUTHORING_GUIDE.md
  • CODE_OF_CONDUCT.md
  • CONTRIBUTING.md
  • LICENSE
  • MAC_SETUP.md
  • Makefile
  • README.md
  • SECURITY.md

# Installation Guide

python
Prerequisites

Setup Steps

git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git

Clone the repository locally.

gcloud auth application-default login

Set up Google Cloud authentication credentials.

python3 -m venv env

Create a virtual environment.

source env/bin/activate

Activate the virtual environment.

pip install -r requirements.txt

Install project dependencies.

python snippets.py

Run the sample script.

Key Commands

pip install -r requirements.txt

Install Python package dependencies specified in requirements.txt.

gcloud auth application-default login

Authenticate the application to access Google Cloud services.

python snippets.py

Run the main script in the sample directory.

Each sample folder may have its own requirements.txt, so check the settings of the folder you want to run.

# Use via CDN

jsDelivr

jsDelivr serves any public GitHub repository as a CDN with zero setup. Pick a version and a file to get a ready-to-paste link and snippet.

Showing a partial file list.

Command Glossary

Commands referenced in this DOCs, explained below.

🔍

gcloud auth

View Details ▼

Grant and revoke authorization to `gcloud` and manage credentials.
See also: `gcloud`.

gcloud auth login

Authorize Google Cloud access for the `gcloud` CLI with Google Cloud user credentials and set the current account as active:

gcloud auth activate-service-account

Authorize Google Cloud access similar to `gcloud auth login` but with service account credentials:

gcloud auth application-default

Manage Application Default Credentials (ADC) for Cloud Client Libraries:

🔍

git clone

View Details ▼

Clone an existing repository.

git clone {{remote_repository_location}} {{path/to/directory}}

Clone an existing repository into a new directory (the default directory is the repository name):

git clone --recursive {{remote_repository_location}}

Clone an existing repository and its submodules:

git clone {{[-n|--no-checkout]}} {{remote_repository_location}}

Clone only the `.git` directory of an existing repository:

🔍

pip install

View Details ▼

Install Python packages.

pip install {{package1 package2 ...}}

Install one or more packages:

pip install {{package1 package2 ...}} {{[-U|--upgrade]}}

Upgrade all specified packages to the latest version, installing any that are not already present:

pip install {{package}}=={{version}}

Install a specific version of a package:

🔍

pip

View Details ▼

Python package manager.
Some subcommands such as `install` have their own usage documentation.

pip install {{package}}

Install a package (see `pip install` for more install examples):

pip install --user {{package}}

Install a package to the user's directory instead of the system-wide default location:

pip install {{[-U|--upgrade]}} {{package}}

Upgrade a package:

🔍

python

View Details ▼

Python language interpreter.

python

Start a REPL (interactive shell):

python {{path/to/file.py}}

Execute a specific Python file:

python -i {{path/to/file.py}}

Execute a specific Python file and start a REPL:

🔍

python3

View Details ▼

This command is an alias of `python`.

tldr python

View documentation for the original command:

🔍

virtualenv

View Details ▼

Create virtual isolated Python environments.

virtualenv {{path/to/venv}}

Create a new environment:

virtualenv --prompt {{prompt_prefix}} {{path/to/venv}}

Customize the prompt prefix:

virtualenv {{[-p|--python]}} {{path/to/pythonbin}} {{path/to/venv}}

Use a different version of Python with virtualenv:

// repository documentation