Skip to main content

Trustpilot API client including CLI tool

Project description

trustpilot

Build Status Latest Version Python Support

Python HTTP client for Trustpilot.

Features

  • Extends the requests.Session class with automatic authentication for public and private endpoints
  • GET, POST, PUT, DELETE, HEAD, OPTIONS and PATCH methods are exposed on module level
  • Implements session factory and default singleton session
  • Provides a simple hook system
  • CLI tool with basic HTTP commands

Installation

Install the package from PyPI using pip:

pip install trustpilot

Usage

(for full usage documentation checkout docs)

from trustpilot import client
client.default_session.setup(
    api_host="https://api.trustpilot.com",
    api_key="YOUR_API_KEY",
)
response = client.get("/foo/bar")
status_code = response.status_code

You can rely on environment variables for the setup of sessions so

$ env
TRUSTPILOT_API_HOST=https://api.trustpilot.com
TRUSTPILOT_API_KEY=foo
TRUSTPILOT_API_SECRET=bar

CLI

The trustpilot_api_client command is bundled with the install

Usage: trustpilot_api_client [OPTIONS] COMMAND [ARGS]...

Options:
  --host TEXT                     Host name
  --version TEXT                  Api version
  --key TEXT                      Api key
  --secret TEXT                   Api secret
  --token_issuer_host TEXT        Token issuer host name
  --username TEXT                 Trustpilot username
  --password TEXT                 Trustpilot password
  -c, --config FILENAME           Json config file name
  -e, --env FILENAME              Dot env file
  -of, --outputformat [json|raw]  Output format, default=json
  -v, --verbose                   Verbosity level
  --help                          Show this message and exit.

Commands:
  create-access-token  Get an access token
  delete               Send a DELETE request
  get                  Send a GET request
  post                 Send a POST request with specified data
  put                  Send a PUT request with specified data

You can also supply the variables with:

--config/-c : As JSON config file in the following format:

{
  "TRUSTPILOT_API_HOST": "foo",
  "TRUSTPILOT_API_KEY": "bar",
  "TRUSTPILOT_API_SECRET": "baz",
  "TRUSTPILOT_API_VERSION": "v1",
  "TRUSTPILOT_USERNAME": "username",
  "TRUSTPILOT_PASSWORD": "password"
}

or --env/-e : As DotEnv config file in the following format:

TRUSTPILOT_API_HOST=foo
TRUSTPILOT_API_KEY=bar
TRUSTPILOT_API_SECRET=baz
TRUSTPILOT_API_VERSION=v1
TRUSTPILOT_USERNAME=username
TRUSTPILOT_PASSWORD=password

Changelog

see HISTORY.md

Issues / DEV

Report issues here and we welcome collaboration through PullRequests :-)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trustpilot-10.0.1.tar.gz (9.1 kB view hashes)

Uploaded Source

Built Distribution

trustpilot-10.0.1-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page