SDKs overview
Userstack, a service for User-Agent string parsing, offers Software Development Kits (SDKs) and libraries designed to streamline the integration of its API into various applications. These tools abstract the underlying HTTP requests and response parsing, allowing developers to focus on utilizing the parsed device, browser, and operating system data rather than managing API communication specifics. Official SDKs are provided for common web development languages, while community contributions extend support to other environments.
An SDK typically includes pre-built functions for making API calls, handling authentication, and deserializing responses into language-specific data structures. For Userstack, this means converting the raw JSON output of a User-Agent string into accessible objects or arrays within a developer's chosen programming language. This approach helps reduce boilerplate code and potential errors in API interaction, which is a common benefit of using an SDK over direct HTTP requests Google API Client Library overview.
The core function of Userstack's API is to accept a User-Agent string as input and return structured data about the client device Userstack API documentation. This data can include details such as browser name and version, operating system name and version, device type (e.g., desktop, mobile, tablet), and brand information. SDKs simplify this process by providing methods to send the User-Agent string and receive the parsed data directly.
Official SDKs by language
Userstack provides official SDKs for several popular programming languages, ensuring direct support and maintenance. These SDKs are maintained by the Userstack team and are the recommended method for integrating the API into applications built with these languages. The official SDKs typically offer the most stable and feature-complete integration experience, reflecting the latest API changes and best practices outlined in the Userstack developer documentation.
The following table outlines the official SDKs available, including their typical package names and installation commands:
| Language | Package Name (or Method) | Installation Command | Maturity / Status |
|---|---|---|---|
| PHP | userstack/userstack-php | composer require userstack/userstack-php |
Stable |
| Python | userstack-python | pip install userstack-python |
Stable |
| jQuery | (Direct inclusion via CDN or file) | <script src="//ajax.googleapis.com/ajax/libs/jquery/3.x.x/jquery.min.js"></script> (then include Userstack JS) |
Stable |
These SDKs are designed to handle common tasks such as API key authentication, constructing API requests, and parsing the JSON responses into native language objects. Using an official SDK can significantly reduce development time and potential integration issues by providing a well-tested and supported interface to the Userstack API.
Installation
Installation procedures for Userstack SDKs vary by programming language and package manager. Below are detailed steps for setting up the official PHP, Python, and jQuery libraries.
PHP SDK Installation
The PHP SDK for Userstack is typically installed using Composer, the dependency manager for PHP. Ensure you have Composer installed on your system before proceeding.
- Install Composer (if not already installed): Refer to the Composer download guide for instructions.
- Navigate to your project directory: Open your terminal or command prompt and change to your PHP project's root directory.
- Require the Userstack PHP SDK: Execute the following command:
composer require userstack/userstack-php
This command will download the SDK and its dependencies, adding them to your vendor/ directory and updating your composer.json and composer.lock files. You can then include Composer's autoloader in your PHP script: require 'vendor/autoload.php';
Python SDK Installation
The Python SDK is installed using pip, the Python package installer. Ensure you have Python and pip installed.
- Ensure pip is up-to-date:
python -m pip install --upgrade pip
- Install the Userstack Python SDK: Execute the following command in your terminal:
pip install userstack-python
This command will download and install the userstack-python package, making it available for import in your Python scripts.
jQuery Library Installation
For jQuery, there isn't a dedicated package manager like Composer or pip for a server-side SDK. Instead, you typically include the jQuery library itself and then write client-side JavaScript to make the API call. Userstack's documentation provides examples for client-side integration using jQuery's AJAX capabilities Userstack client-side examples.
- Include jQuery in your HTML: Add the following script tag to the
<head>or before the closing</body>tag in your HTML file:
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
- Write client-side JavaScript: After jQuery is loaded, you can use its AJAX functions to interact with the Userstack API.
Quickstart example
This section provides a quickstart example demonstrating how to use the Userstack API with its official SDKs. The examples will show how to initialize the client and make a basic API call to parse a User-Agent string.
To use these examples, you will need a Userstack API access key. You can obtain one by signing up on the Userstack dashboard. The free tier offers 10,000 requests per month, which is sufficient for initial testing and development.
PHP Quickstart
After installing the PHP SDK via Composer, you can make an API call as follows:
<?php
require 'vendor/autoload.php';
use userstack\userstack;
// Replace with your actual API access key
$access_key = 'YOUR_ACCESS_KEY';
// Initialize the Userstack client with your access key
$userstack = new userstack($access_key);
// The User-Agent string to parse (you can get this from $_SERVER['HTTP_USER_AGENT'])
$user_agent_string = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36';
try {
// Make the API call to parse the User-Agent string
$result = $userstack->detect($user_agent_string);
// Output the parsed data
echo '<pre>';
print_r($result);
echo '</pre>';
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
?>
This PHP snippet initializes the userstack client with your API key and then calls the detect method with a sample User-Agent string. The parsed data is then printed to the console or browser.
Python Quickstart
After installing the Python SDK via pip, you can make an API call:
import userstack
# Replace with your actual API access key
ACCESS_KEY = 'YOUR_ACCESS_KEY'
# Initialize the Userstack client with your access key
client = userstack.Client(ACCESS_KEY)
# The User-Agent string to parse
user_agent_string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36'
try:
# Make the API call to parse the User-Agent string
result = client.detect(user_agent_string)
# Output the parsed data
print(result)
except userstack.UserstackException as e:
print(f"Error: {e}")
This Python example creates an instance of the userstack.Client and uses its detect method to parse the User-Agent string, printing the resulting dictionary.
jQuery Quickstart (Client-Side)
For client-side integration with jQuery, you would make an AJAX request directly to the Userstack API endpoint:
<script>
$(document).ready(function() {
// Replace with your actual API access key
const ACCESS_KEY = 'YOUR_ACCESS_KEY';
// Get the current User-Agent string from the browser
const userAgent = navigator.userAgent;
// Construct the API endpoint URL
const apiUrl = `https://api.userstack.com/detect?access_key=${ACCESS_KEY}&ua=${encodeURIComponent(userAgent)}`;
$.ajax({
url: apiUrl,
method: 'GET',
dataType: 'json',
success: function(data) {
console.log('Parsed User-Agent Data:', data);
// You can now use the 'data' object to display information on your webpage
$('#user-agent-info').text(JSON.stringify(data, null, 2));
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Error fetching User-Agent data:', textStatus, errorThrown);
$('#user-agent-info').text('Error fetching data.');
}
});
});
</script>
<!-- A placeholder element to display the result -->
<pre id="user-agent-info">Loading User-Agent data...</pre>
This JavaScript snippet uses jQuery's $.ajax function to send a GET request to the Userstack API, including the current browser's User-Agent string. The response is then logged to the console and displayed on the webpage.
Community libraries
While Userstack provides official SDKs, the developer community often contributes libraries and wrappers for other languages or frameworks. These community-driven projects can offer alternative ways to interact with the API, sometimes tailored to specific use cases or development environments not covered by official support.
Community libraries are typically found on platforms like GitHub, npm, or PyPI, and their quality and maintenance levels can vary. Developers should exercise due diligence when choosing a community library, checking for active maintenance, clear documentation, and a strong community backing. It is advisable to review the source code and ensure it aligns with the Userstack API specifications and security best practices, particularly regarding API key handling.
As of 2026, specific widely-adopted community libraries for Userstack beyond the officially listed ones are not prominently documented by Userstack itself. Developers interested in contributing or finding community-developed solutions are encouraged to search public code repositories or developer forums. For example, a search on GitHub for "userstack client" or "userstack library" might yield relevant results from independent developers.
When integrating any third-party library, developers should evaluate its licensing, security implications, and compatibility with their project's requirements. For critical applications, relying on the official documentation and making direct HTTP requests or using the officially supported SDKs is generally recommended to ensure stability and direct support from the Userstack team.