Getting Started

Installation

The Perspective Python Wrapper can be installed using pip.

pip install perspective

The latest version of this package can be installed using this command:

pip install --upgrade https://github.com/conway/perspective/archive/master.zip

Acquiring an API Key

Perspective is still in beta. API keys are available by request here (click on “Request API Access”). If your request is approved, you will receive a message by email from Google.

To get your API key once the request has been approved, navigate to the Google API Console and create a new project. Then go to the Perspective Overview Page to enable the API. Finally, go to your project’s credential page, click “Create credentials”, and select “API key” from the dropdown menu. A popup will be shown containing your API key. Copy this, and don’t share it with anyone.

Basic Usage

Using the API key you’ve acquired, it’s simple to make a Perspective instance.

from perspective import Perspective

perspective = Perspective("api_key") # replace with your actual key

Comments can be evaluated using Perspective.score, as demonstrated below.

from perspective import Perspective

perspective = Perspective("api_key") # replace with your actual key
comment_body = "text"
comment = perspective.score(comment_body, tests=["TOXICITY"])
print("Toxicity score: " + comment["TOXICITY"].score)