Introducing UA-Extract: Simplify and Modernize User-Agent Parsing for Your Applications
In the dynamic world of web development, accurately detecting user devices, browsers, and operating systems is crucial for delivering tailored experiences and insightful analytics. To help developers stay ahead of the curve, we present UA-Extractโa robust Python library engineered to streamline user-agent string analysis and keep your device detection techniques current with minimal effort.
What is UA-Extract?
UA-Extract is a high-performance Python toolkit designed to interpret user-agent strings efficiently and precisely. Built atop the renowned device_detector framework, it leverages an extensive and regularly updated database of regex patterns to recognize a vast array of browsers, platforms, and devicesโranging from common smartphones to niche gadgets like smart TVs and gaming consoles.
The core advantage? Automatic and effortless updates of regex patterns. As new devices and browsers launch, existing detection scripts tend to become outdated. UA-Extract addresses this by enabling seamless regex refreshes with just a single line of code or a straightforward command-line instruction. It synchronizes with the community-driven Matomo Device Detector project, ensuring your detection logic remains accurate without manual maintenance burdens.
Key Features and Usage
- Simplified Regex Updates
Keep your device identification algorithms current effortlessly:
python
from ua_extract import Regexes
Regexes().update_regexes() # Fetches the latest regex patterns
Alternatively, via CLI:
bash
ua_extract update_regexes
- Detailed User-Agent Parsing
Extract comprehensive device details with minimal code:
“`python
from ua_extract import DeviceDetector
ua_string = ‘Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 EtsyInc/5.22 rv:52200.62.0’
detection = DeviceDetector(ua_string).parse()
print(detection.os_name()) # e.g., iOS
print(detection.device_model()) # e.g., iPhone
print(detection.secondary_client_name()) # e.g., EtsyInc
“`
For faster processing, especially when bot detection is unnecessary, consider using the lightweight SoftwareDetector
variant to focus on essential OS and application info.
- Speed and Efficiency
UA-Extract optimizes speed through in-memory caching and supports optional modules like the regex module for faster parsing. This setup makes it