Skip to main content

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:
    ...

Metadata

Release files for vonage-http-client 1.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vonage-http-client 1.5.2
File Size Uploaded
vonage_http_client-1.5.2.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vonage-http-client 1.5.2
File Interpreter ABI Platform
vonage_http_client-1.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / vonage_http_client-1.5.2.tar.gz

Download URL vonage_http_client-1.5.2.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
252dc672365159ba48b6b63134032561dfa34616e4ccb1d12785e81e09ccff37
BLAKE2b-256 checksum
How to use checksums
1b8a1456896a5ea1c8136b378288847eea33ef3db44d57e501fd39e5462c7cdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.3

Release files / vonage_http_client-1.5.2-py3-none-any.whl

Download URL vonage_http_client-1.5.2-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2fbdc700c82380ce1568affa72c9524877cd69e5e967ebec8e913bbad5b890c6
BLAKE2b-256 checksum
How to use checksums
552499c81ff988987cbf0adc3236164466d1f9319aabdb5d2486b4eb6b7e0f93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.5.2 This release

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page