Skip to main content

An HTTP client for making requests to Vonage APIs.

Project description

Vonage HTTP Client Package

This Python package provides a synchronous HTTP client for sending authenticated requests to Vonage APIs.

This package (vonage-http-client) is used by the vonage Python package and SDK so doesn't require manual installation or config unless you're using this package independently of a SDK.

The HttpClient class is initialized with an instance of the Auth class for credentials, an optional class of HTTP client options, and an optional SDK version (this is provided automatically when using this module via an SDK).

The HttpClientOptions class defines the options for the HTTP client, including the API and REST hosts, timeout, pool connections, pool max size, and max retries.

This package also includes an Auth class that allows you to manage API key- and secret-based authentication as well as JSON Web Token (JWT) authentication.

For full API documentation refer to the Vonage Developer documentation.

Installation (if not using via an SDK)

You can install the package using pip:

pip install vonage-http-client

Usage

from vonage_http_client import HttpClient, HttpClientOptions
from vonage_http_client.auth import Auth

# Create an Auth instance
auth = Auth(api_key='your_api_key', api_secret='your_api_secret')

# Create HttpClientOptions instance
options = HttpClientOptions(api_host='api.nexmo.com', timeout=30)

# Create a HttpClient instance
client = HttpClient(auth=auth, http_client_options=options)

# Make a GET request
response = client.get(host='api.nexmo.com', request_path='/v1/messages')

# Make a POST request
response = client.post(host='api.nexmo.com', request_path='/v1/messages', params={'key': 'value'})

Get the Last Request and Last Response from the HTTP Client

The HttpClient class exposes two properties, last_request and last_response that cache the last sent request and response.

# Get last request, has type requests.PreparedRequest
request = client.last_request

# Get last response, has type requests.Response
response = client.last_response

Appending to the User-Agent Header

The HttpClient class also supports appending additional information to the User-Agent header via the append_to_user_agent method:

client.append_to_user_agent('additional_info')

Changing the Authentication Method Used

The HttpClient class automatically handles JWT and basic authentication based on the Auth instance provided. It uses JWT authentication by default, but you can specify the authentication type when making a request:

# Use basic authentication for this request
response = client.get(host='api.nexmo.com', request_path='/v1/messages', auth_type='basic')

Catching errors

Error objects are exposed in the package scope, so you can catch errors like this:

from vonage_http_client import HttpRequestError

try:
    client.post(...)
except HttpRequestError:
    ...

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

vonage_http_client-1.5.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

vonage_http_client-1.5.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file vonage_http_client-1.5.1.tar.gz.

File metadata

  • Download URL: vonage_http_client-1.5.1.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.4

File hashes

Hashes for vonage_http_client-1.5.1.tar.gz
Algorithm Hash digest
SHA256 a5e95c4e97730b8faade4a55db84d000c1376c769804f14728337651bd4a715e
MD5 d490c7e8d2db14c819a4259dd30d49cd
BLAKE2b-256 6d488c8a17ce540b90a7ed5cfe6bd0b49bf26c4cc3688a07e4a7174a68f8ea75

See more details on using hashes here.

File details

Details for the file vonage_http_client-1.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for vonage_http_client-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d7f7692eb8473646b3a986e3ba0fba3c5e1006ee3a2d33279ad1f71ba02bf5aa
MD5 5884bba1ad6b58c5d35d69a691f043e2
BLAKE2b-256 2fb8371c6ce99b6eb7d53466bf94f2b3db3e9eefaa9f2e698ed2d9d44c30045a

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