Skip to content

Introduction & basic usage

Yılmaz Alpaslan edited this page Jan 11, 2022 · 1 revision

Introduction

Welcome to the perspective.py wiki! In this page, you can find information about how the library basically works and some example codes. As an API wrapper is made to make it easier to access APIs, it's not rocket science. I'm trying to improve the library's ease-of-usage all the time and keep it simple as possible. However, the library is still object-oriented and you may need to know basics of Python to be able to use this library (such as what are instances or how object properties work). At least I recommend you to know for a better start.

Installation

If you haven't installed the library yet, you can install it by running python -m pip install --upgrade perspective.py command in command prompt (in case Scripts folder is not in PATH and you already have an older version of library installed), or simply run pip install perspective.py.

Importing the package

Although the library's name is perspective.py in PyPI (Python Package Index), you need to import the package with perspective name without .py at the end as Python does not support dots in package names.

You can either simply import the package by the following command:

import perspective

Or you can import the classes from the package using the below command:

from perspective import Client, Attributes, utils

Classes of the package

To avoid confusion, I've decided to separate functions and other classes from each other, into different classes (such as Client, Attributes or utils).

perspective.Client

This class contains the analyze function which you will use to make a request to the API. You also need to enter your API token which you can get by reading this article while creating an instance of this class.

perspective.Attributes

This class simply contains the attributes that you can request to the API for analysis (such as TOXICITY or INSULT), however, you can also use string versions of attributes instead of nested classes of this class as those nested classes already return a string in its __repr__ function.

perspective.utils

This class comes with some cool functions that you don't really need but may want to use, such as format_response or save_graph. These functions might be useful when creating an interactive application for end user.

Basic usage

In order to make requests to the API, you need to create an instance of perspective.Client object/class.

i have to sleep for now i'ma continue tomorrow