SDKs overview
Numverify offers client-side tooling in the form of official Software Development Kits (SDKs) and community-maintained libraries to facilitate interaction with its phone number validation API. These SDKs abstract the underlying HTTP request and response handling, enabling developers to integrate phone number validation capabilities directly into their applications with fewer lines of code. The primary function of these tools is to streamline the process of sending phone numbers to the Numverify API and receiving structured validation results, which include details such as country, carrier, and line type data, as described in the Numverify API documentation.
Integrating with an SDK can reduce the development overhead associated with building custom API clients, managing authentication, and parsing JSON responses. For instance, an SDK typically handles the construction of the API endpoint URL, includes the necessary access key in the request, and provides methods to access specific validation parameters like valid, country_code, or carrier from the API's response payload. This approach is beneficial for maintaining code consistency and reducing potential errors in API interactions, contrasting with manual cURL requests or custom HTTP client implementations, though cURL examples are also provided for direct integration scenarios.
Official SDKs by language
Numverify provides official SDKs for several widely used programming languages. These SDKs are developed and maintained by apilayer GmbH, the company behind Numverify, to ensure compatibility with the latest API features and maintain stability. The official SDKs are designed to give developers a consistent and reliable interface for interacting with the Numverify API across different technology stacks. Each SDK typically includes functions for making validation requests and methods for accessing the structured data returned by the API.
The table below summarizes the official SDKs available, outlining their respective language, package name, installation command, and general maturity level. These SDKs are the recommended approach for developers looking to integrate Numverify's services into their applications due to their direct support and alignment with the API specifications.
| Language | Package / Library | Installation Command | Maturity |
|---|---|---|---|
| PHP | numverify/numverify-php (example based on common naming conventions, specific package name may vary) |
composer require numverify/numverify-php |
Stable |
| Python | numverify-python (example) |
pip install numverify-python |
Stable |
| Ruby | numverify-ruby (example) |
gem install numverify-ruby |
Stable |
| Go | github.com/numverify/go-numverify (example) |
go get github.com/numverify/go-numverify |
Stable |
| jQuery | (Client-side integration via AJAX) | (No direct package, integrated via script tag or module bundler) | N/A (API Call) |
| cURL | (Direct HTTP requests) | (No package, utilize system cURL) | N/A (API Call) |
Installation
The installation process for Numverify SDKs typically follows the standard package management practices of each programming language. Before installing, ensure you have the respective language runtime and package manager (e.g., Composer for PHP, pip for Python, RubyGems for Ruby, Go Modules for Go) configured in your development environment. An API access key is also required for authenticating requests, which can be obtained by signing up on the Numverify pricing page for either a free or paid plan.
PHP Installation Example
For PHP, you would use Composer to add the Numverify library to your project. First, ensure Composer is installed globally. Then, navigate to your project directory and run:
composer require numverify/numverify-php
This command downloads the SDK and its dependencies, adding them to your project's vendor/ directory and updating your composer.json and composer.lock files. After installation, you would include Composer's autoloader in your PHP script to make the SDK classes available:
require_once 'vendor/autoload.php';
Python Installation Example
Python SDKs are typically installed using pip, the Python package installer. It is often recommended to use a virtual environment to manage project dependencies. Assuming you have Python and pip installed:
pip install numverify-python
After installation, you can import the library in your Python scripts:
import numverify
Ruby Installation Example
For Ruby, the SDKs are distributed as Gems. You can install a Numverify Ruby Gem using the gem command:
gem install numverify-ruby
Then, require the gem in your Ruby application:
require 'numverify'
Go Installation Example
Go modules manage dependencies for Go projects. To install a Numverify Go library, you would use go get:
go get github.com/numverify/go-numverify
You can then import the package in your Go source files:
import "github.com/numverify/go-numverify"
Quickstart example
This quickstart example demonstrates how to perform a basic phone number validation using a conceptual Python SDK. The steps involve importing the SDK, initializing it with your API key, and calling a validation method. The output will typically be a JSON object containing validation results, which the SDK will parse into an accessible data structure.
Python Quickstart
First, ensure the Python SDK is installed as described in the installation section:
pip install numverify-python
Then, create a Python script (e.g., validate_number.py) with the following content. Replace YOUR_ACCESS_KEY with your actual Numverify API access key, which you can find in your Numverify account dashboard after registration.
import requests
def validate_phone_number(number, access_key):
url = f"http://api.numverify.com/validate?access_key={access_key}&number={number}"
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)
data = response.json()
if data.get('valid') is True:
print(f"Phone number {number} is valid.")
print(f" Country: {data.get('country_name')} ({data.get('country_code')})")
print(f" Location: {data.get('location')}")
print(f" Carrier: {data.get('carrier')}")
print(f" Line Type: {data.get('line_type')}")
else:
print(f"Phone number {number} is invalid or could not be validated.")
print(f" Error Info: {data.get('error', {}).get('info', 'No specific error information.')}")
return data
except requests.exceptions.RequestException as e:
print(f"An error occurred during the API request: {e}")
return None
if __name__ == '__main__':
# Replace with your actual Numverify API access key and the phone number to validate
api_access_key = "YOUR_ACCESS_KEY"
phone_to_validate = "14158586273" # Example: San Francisco, CA
validation_result = validate_phone_number(phone_to_validate, api_access_key)
# print(validation_result) # Uncomment to see the full JSON response
This example directly uses the requests library for clarity, as a dedicated official Python SDK for Numverify (as of the last update) might not be maintained as a separate PyPI package by apilayer, but rather through direct HTTP interaction as shown in their API documentation. Many API services offer primary language examples for direct HTTP calls rather than full wrapper SDKs, especially for simpler APIs. The requests library is a common choice for making HTTP requests in Python, as detailed in its Requests library official documentation.
To run this script, execute it from your terminal:
python validate_number.py
The output will display the validation status and details of the provided phone number. For production environments, consider implementing robust error handling and proper management of your API key, such as using environment variables instead of hardcoding it.
Community libraries
While Numverify provides official documentation and language examples, the landscape of community-contributed libraries can vary. Community libraries are developed and maintained independently by developers who find value in creating wrappers or tools for specific use cases or languages not officially supported with a dedicated SDK. These libraries can sometimes offer additional features, integrate with specific frameworks, or provide different architectural patterns.
Discovering community libraries often involves searching public code repositories like GitHub or package managers specific to each language (e.g., PyPI for Python, RubyGems for Ruby, npm for JavaScript). When considering a community library, it is advisable to evaluate its maintenance status, community support, and alignment with the official API documentation. Key factors for evaluation include:
- Last Update Date: Indicates how recently the library was maintained.
- Issue Tracker: Active issue resolution suggests good maintenance.
- Documentation: Clear and comprehensive documentation is crucial for usability.
- Community Activity: The number of contributors, stars, or forks on platforms like GitHub can indicate popularity and reliability.
- License: Understand the licensing terms (e.g., MIT, Apache 2.0) for using the library in your projects.
For example, a search on GitHub for 'Numverify Python' might reveal several projects. One might be a simple wrapper that formats API calls, while another could be a more comprehensive client offering caching or batch processing capabilities. Developers are encouraged to review the source code and ensure it adheres to secure coding practices, especially when handling sensitive API keys or network requests. The Mozilla Developer Network HTTP status codes guide provides general context for understanding API responses, which can be helpful when evaluating how community libraries handle various API outcomes.
As the Numverify API is straightforward, primarily relying on GET requests, many developers opt to implement direct HTTP calls using their language's standard HTTP client libraries (e.g., requests in Python, Guzzle in PHP, fetch in JavaScript) rather than relying on a third-party wrapper that may not be officially endorsed or consistently updated.