Skip to main content

Python API Wrapper for the CallHub API

Project description

CallHub Python Wrapper

Build Status Coverage Status PyPI - Downloads

CallHub API Client Wrapper for Python

Creates a clean(er) python interface to several important functions of the CallHub API.

project-logo

Installation

pip install callhub-python-wrapper

Requires Python 3.5 or higher

Features

  • Built-in (optional) ratelimiting that respects CallHub's varying rate limits for different functions
  • Better error handling for uploading contacts with fields that don't exist in CallHub
  • Abstracted away some tedious parts of using CallHub's API. When uploading contacts, CallHub wants you to map CSV columns to the ids of each field in CallHub, which is difficult and easy to mess up. This wrapper handles all of that by matching on field names.
  • Automatically handles paging when doing bulk fetching
  • Uses async requests to improve speed for repetitive calls (implemented in get_contacts)

Currently implemented

  • Bulk create contacts
  • Get agent leaderboard
  • Get all fields and IDs (including custom fields)
  • Bulk get contacts and fields
  • Create single contact

Implemented but not in latest release

  • Get all phone numbers on DNC list
  • Get all DNC lists
  • Add/remove numbers to/from DNC list(s)
  • Create and delete DNC lists

Currently on roadmap

  • Create phonebook
  • Create/get/delete webhook
  • Create/get teams
  • Add/delete agent to/from team
  • Create/delete agent

Usage

import callhub
callhub = CallHub(api_key="123456789ABCDEF")
phonebook_id = 6545324
contacts = [{'first name': 'Sumiya', 'phone number':'5555555555', 'mobile number': '5555555555'},
           {'first name': 'Joe', 'phone number':'5555555555', 'mobile number':'5555555555'}]
country_iso = "CA"

# Create multiple contacts
callhub.bulk_create(phonebook_id, contacts, country_iso)

# Create single contact
callhub.create_contact(contacts[0])

# Get all contacts (up to a user-specified limit)
callhub.get_contacts(limit=1000000)

# Get names and ids of all do-not-contact lists
callhub.get_dnc_lists()

# Get all phone numbers marked do-not-contact and the do-not
# contact list(s) that they are associated with
callhub.get_dnc_phones()

# Add phone number 555-555-5555 to DNC list 123456789
callhub.add_dnc(["5555555555"], "123456789")

# Add multiple phone numbers to dnc list 12345689
callhub.add_dnc(["5555555555","5554443333"], "123456789")

Performance Notes

Bulk creating contacts works differently from most other functions

This takes advantage of CallHub's built in bulk_create API endpoint, so expect equivalent speeds to uploading a spreadsheet of contacts as a normal admin user. Note that bulk_create can only be called once every 70 seconds to comply with a special CallHub ratelimit on this endpoint.

It's faster to call add_dnc with ten numbers than to call add_dnc with one number ten times

If you use this library to make looping calls on most functions (e.g. add_dnc), you can expect a performance of about 1 request/second. This is because all functions wait until they receives a response from the server before exiting.

However, you can get much faster performance if you call add_dnc with a list of ten contacts (as opposed to ten times with one contact each time). This is because every function that does many similar repetitive API calls leverages async requests for repetitive calls (makes a large batch of requests and then waits for that pool of requests to finish.) Because of this, we can achieve real-world speeds of adding 10 numbers to a DNC list per second for large batches of numbers (CallHub's API limit is 20/s).

Fetching contacts with get_contacts can take a while

CallHub only gives us 10 contacts per api request when using get_contacts, so expect this script to fetch contacts at about 100 contacts/s. That's about 17 minutes to fetch 100K contacts!

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

callhub-python-wrapper-0.2.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

callhub_python_wrapper-0.2.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file callhub-python-wrapper-0.2.0.tar.gz.

File metadata

  • Download URL: callhub-python-wrapper-0.2.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

File hashes

Hashes for callhub-python-wrapper-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7b1b9aefd6c2558033a843a3b9cb9da7b882fdba2ce2674dbde92b696848baf3
MD5 fb6f2abf4183aed1d130e74e9c83816c
BLAKE2b-256 fab6fada01cdac3ba9c524e5e371ea1eb8a6d41b419a9519c1472fb63ed8f410

See more details on using hashes here.

File details

Details for the file callhub_python_wrapper-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: callhub_python_wrapper-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

File hashes

Hashes for callhub_python_wrapper-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5f4a9f41ac38bd65b791675da794576119617e8ea3505b9fe547c9ace9bf8fb
MD5 161bc7bdb780a88d110b864415338066
BLAKE2b-256 1f7cebc8e6a7fb39a7b8a35cf4d45ee3015bd9dc30cd43702695640a3aa2ea84

See more details on using hashes here.

Supported by

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