Skip to main content
Scrappy, the SCRAPI mascot!

Python Dialogflow CX Scripting API (SCRAPI)

A high level scripting API for bot builders, developers, and maintainers.

Table of Contents
  1. Introduction
  2. Getting Started
  3. Usage
  4. Library Composition
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

Introduction

The Python Dialogflow CX Scripting API (DFCX SCRAPI) is a high level API that extends the official Google Python Client for Dialogflow CX. SCRAPI makes using DFCX easier, more friendly, and more pythonic for bot builders, developers, and maintainers.

SCRAPI --> Python Dialogflow CX
as
Keras --> Tensorflow

What Can I Do With DFCX SCRAPI?

With DFCX SCRAPI you can perform many bot building and maintenance actions at scale including, but not limited to:

  • Create, Update, Delete, Get, and List for all CX resources types (i.e. Intents, Entity Types, Pages, Flows, etc.)
  • Convert commonly accessed CX Resources to Pandas Dataframes
  • Have fully automated conversations with a CX agent (powerful for regression testing!)
  • Extract Validation information
  • Extract Change History information
  • Search across all Flows/Pages/Routes to find a specific parameter or utterance using Search Util functions
  • Quickly move CX resources between agents using Copy Util functions!
  • Build the fundamental protobuf objects that CX uses for each resource type using Builder methods
  • ...and much, much more!

Built With

  • Python 3.8+

Authentication

Authentication can vary depending on how and where you are interacting with SCRAPI.

Google Colab

If you're using SCRAPI with a Google Colab notebook, you can add the following to the top of your notebook for easy authentication:

project_id = '<YOUR_GCP_PROJECT_ID>'

# this will launch an interactive prompt that allows you to auth with GCP in a browser
!gcloud auth application-default login --no-launch-browser

# this will set your active project to the `project_id` above
!gcloud auth application-default set-quota-project $project_id

After running the above, Colab will pick up your credentials from the environment and pass them to SCRAPI directly. No need to use Service Account keys! You can then use SCRAPI simply like this:

from dfcx_scrapi.core.intents import Intents

agent_id = '<YOUR_AGENT_ID>'
i = Intents() # <-- Creds will be automatically picked up from the environment
intents_map = i.get_intents_map(agent_id)

Cloud Functions / Cloud Run

If you're using SCRAPI with Cloud Functions or Cloud Run, SCRAPI can pick up on the default environment creds used by these services without any additional configuration!

  1. Add dfcx-scrapi to your requirements.txt file
  2. Ensure the Cloud Function / Cloud Run service account has the appropriate Dialogflow IAM Role

Once you are setup with the above, your function code can be used easily like this:

from dfcx_scrapi.core.intents import Intents

agent_id = '<YOUR_AGENT_ID>'
i = Intents() # <-- Creds will be automatically picked up from the environment
intents_map = i.get_intents_map(agent_id)

Local Python Environment

Similar to Cloud Functions / Cloud Run, SCRAPI can pick up on your local authentication creds if you are using the gcloud CLI.

  1. Install gcloud CLI.
  2. Run gcloud init.
  3. Run gcloud auth login
  4. Run gcloud auth list to ensure your principal account is active.

This will authenticate your principal GCP account with the gcloud CLI, and SCRAPI can pick up the creds from here.


Exceptions and Misc.

There are some classes in SCRAPI which still rely on Service Account Keys, notably the DataframeFunctions class due to how it authenticates with Google Sheets.

In order to use these functions, you will need a Service Account that has appropriate access to your GCP project.
For more information and to view the official documentation for service accounts go to Creating and Managing GCP Service Accounts.

Once you've obtained a Service Account Key with appropriate permissions, you can use it as follows:

from dfcx_scrapi.core.intents import Intents
from dfcx_scrapi.tools.dataframe_functions import DataframeFunctions

agent_id = '<YOUR_AGENT_ID>'
creds_path = '<PATH_TO_YOUR_SERVICE_ACCOUNT_JSON_FILE>'

i = Intents(creds_path=creds_path)
dffx = DataframeFunctions(creds_path=creds_path)

df = i.bulk_intent_to_df(agent_id)
dffx.dataframe_to_sheets('GOOGLE_SHEET_NAME', 'TAB_NAME', df)

Getting Started

Environment Setup

Set up Google Cloud Platform credentials and install dependencies.

gcloud auth login
gcloud auth application-default login
gcloud config set project <project name>
python3 -m venv venv
source ./venv/bin/activate
pip install -r requirements.txt

Usage

To run a simple bit of code you can do the following:

  • Import a Class from dfcx_scrapi.core
  • Assign your Service Account to a local variable
from dfcx_scrapi.core.intents import Intents

creds_path = '<PATH_TO_YOUR_SERVICE_ACCOUNT_JSON_FILE>'
agent_path = '<FULL_DFCX_AGENT_ID_PATH>'

# DFCX Agent ID paths are in this format:
# 'projects/<project_id>/locations/<location_id>/agents/<agent_id>'

# Instantiate your class object and pass in your credentials
i = Intents(creds_path, agent_id=agent_path)

# Retrieve all Intents and Training Phrases from an Agent and push to a Pandas DataFrame
df = i.bulk_intent_to_df()

Library Composition

Here is a brief overview of the SCRAPI library's structure and the motivation behind that structure.

Core

The Core folder is synonymous with the core Resource types in the DFCX Agents (agents, intents, flows, etc.)

  • This folder contains the high level building blocks of SCRAPI
  • These classes and methods can be used to build higher level methods or custom tools and applications

Tools

The Tools folder contains various customized toolkits that allow you to do more complex bot management tasks, such as

  • Manipulate Agent Resource types into various DataFrame structures
  • Copy Agent Resources between Agents and GCP Projects on a resource by resource level
  • Move data to and from DFCX and other GCP Services like BigQuery, Sheets, etc.
  • Create customized search queries inside of your agent resources

Builders

The Builders folder contains simple methods for constructing the underlying protos in Dialogflow CX

  • Proto objects are the fundamental building blocks of Dialogflow CX
  • Builder classes allow the user to construct Dialogflow CX resource offline without any API calls
  • Once the resource components are constructed, they can then be pushed to a live Dialogflow CX agent via API

Contributing

We welcome any contributions or feature requests you would like to submit!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the Apache 2.0 License. See LICENSE for more information.

Contact

Patrick Marlow - pmarlow@google.com - @kmaphoenix
Milad Tabrizi - miladt@google.com - @MRyderOC

Project Link: https://github.com/GoogleCloudPlatform/dfcx-scrapi

Acknowledgements

Dialogflow CX Python Client Library
Hugging Face - Pegasus Paraphrase

Metadata

Release files for dfcx-scrapi 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dfcx-scrapi 2.0.0
File Size Uploaded Provenance
dfcx_scrapi-2.0.0.tar.gz 1.9 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dfcx-scrapi 2.0.0
File Interpreter ABI Platform
dfcx_scrapi-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 2.1 MB

Release files / dfcx_scrapi-2.0.0.tar.gz

Download URL dfcx_scrapi-2.0.0.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
5070b47ed2419c3abf6e83ecf4b8d64fe9fd4de4331dcf52b204a595d96a46fc
BLAKE2b-256 checksum
How to use checksums
d445172bb51864dcf7f39513262e1e9a2d3b51a66f4206a7fc8f12bcdbc84501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / dfcx_scrapi-2.0.0-py3-none-any.whl

Download URL dfcx_scrapi-2.0.0-py3-none-any.whl
Size 264.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f451a1ad47c36b4174610f5c1bfbd46fc26ade4d673d0bb5ac086020258c306
BLAKE2b-256 checksum
How to use checksums
a0b2bdbd70277e4ad050c777dc24528e0bad1e50acff6b783014e1a02ba800f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Security for dfcx-scrapi 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page