Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Google Cloud IoT Core Python Samples

This directory contains samples for Google Cloud IoT Core. Google Cloud IoT Core allows developers to easily integrate Publish and Subscribe functionality with devices and programmatically manage device authorization.



This sample requires you to have authentication setup. Refer to the Authentication Getting Started Guide for instructions on setting up credentials for applications.

Install Dependencies

  1. Clone python-docs-samples and change directory to the sample directory you want to use.

    $ git clone
  2. Install pip and virtualenv if you do not already have them. You may want to refer to the Python Development Environment Setup Guide for Google Cloud Platform for instructions.

  3. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.

    $ virtualenv env
    $ source env/bin/activate
  4. Install the dependencies needed to run the samples.

    $ pip install -r requirements.txt



To run this sample:

$ python

usage: [-h] [--cloud_region CLOUD_REGION]
                  [--pubsub_topic PUBSUB_TOPIC] [--config CONFIG]
                  [--device_id DEVICE_ID]
                  [--ec_public_key_file EC_PUBLIC_KEY_FILE]
                  [--project_id PROJECT_ID] [--registry_id REGISTRY_ID]
                  [--rsa_certificate_file RSA_CERTIFICATE_FILE]
                  [--service_account_json SERVICE_ACCOUNT_JSON]
                  [--version VERSION] [--member MEMBER] [--role ROLE]

Example of using the Google Cloud IoT Core device manager to administer

Usage example:

    python \
      --project_id=my-project-id \
      --cloud_region=us-central1 \
      --service_account_json=$HOME/service_account.json \

positional arguments:
    create-es256        Create a new device with the given id, using ES256 for
    create-registry     Gets or creates a device registry.
    create-rsa256       Create a new device with the given id, using RS256 for
    create-topic        Creates a PubSub Topic and grants access to Cloud IoT
    create-unauth       Create a new device without authentication.
    delete-device       Delete the device with the given id.
    delete-registry     Deletes the specified registry.
    get                 Retrieve the device with the given id.
                        Lists versions of a device config in descending order
                        (newest first).
                        Retrieves IAM permissions for the given registry.
    get-registry        Retrieves a device registry.
    get-state           Retrieve a device's state blobs.
    list                List all devices in the registry.
    list-registries     List all registries in the project.
    patch-es256         Patch the device to add an ES256 public key to the
    patch-rs256         Patch the device to add an RSA256 public key to the
    set-config          Patch the device to add an RSA256 public key to the
                        Sets IAM permissions for the given registry to a
                        single role/member.

optional arguments:
  -h, --help            show this help message and exit
  --cloud_region CLOUD_REGION
                        GCP cloud region
  --pubsub_topic PUBSUB_TOPIC
                        Google Cloud Pub/Sub topic. Format is
  --config CONFIG       Configuration sent to a device.
  --device_id DEVICE_ID
                        Device id.
  --ec_public_key_file EC_PUBLIC_KEY_FILE
                        Path to public ES256 key file.
  --project_id PROJECT_ID
                        GCP cloud project name.
  --registry_id REGISTRY_ID
                        Registry id. If not set, a name will be generated.
  --rsa_certificate_file RSA_CERTIFICATE_FILE
                        Path to RS256 certificate file.
  --service_account_json SERVICE_ACCOUNT_JSON
                        Path to service account json file.
  --version VERSION     Version number for setting device configuration.
  --member MEMBER       Member used for IAM commands.
  --role ROLE           Role used for IAM commands.
You can’t perform that action at this time.