Introducing UA-Extract: Simplifying User-Agent Parsing with Automatic Regex Updates
In todayโs digital landscape, accurately identifying browsers, operating systems, and devices through user agent strings is vital for web developers and analytics professionals. Recognizing this need, we are pleased to present UA-Extractโa powerful, Python-based library designed to streamline user agent parsing while ensuring your device recognition remains current with minimal effort.
What Is UA-Extract?
UA-Extract is an efficient and dependable Python tool that specializes in dissecting user agent strings to determine the device, browser, and OS details. Built upon the robust device_detector library, UA-Extract taps into a comprehensive, continually maintained database of user agent regex patterns. This enables it to decipher a wide array of user agents, from mainstream browsers to niche devices such as smart TVs and gaming consoles.
A standout feature is its seamless approach to regex management. As new devices and browsers are released regularly, outdated regexes can lead to misclassification. UA-Extract addresses this challenge by allowing developers to effortlessly refresh regex patternsโeither through a simple code command or a command-line interfaceโby pulling updates directly from the reputable Matomo Device Detector project. This ensures your detection logic stays current without the cumbersome process of manual regex editing.
Hereโs a quick example of updating your patterns:
python
from ua_extract import Regexes
Regexes().update_regexes() # Fetch the latest regex updates
Or via command line:
bash
ua_extract update_regexes
Once updated, you can parse user agents to extract detailed device information:
“`python
from ua_extract import DeviceDetector
user_agent = ‘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’
detector = DeviceDetector(user_agent).parse()
print(detector.os_name()) # e.g., iOS
print(detector.device_model()) # e.g., iPhone
print(detector.secondary_client_name()) # e.g., EtsyInc
“`
For specific use cases focusing on performance, using modules like SoftwareDetector can speed up parsing by sidestepping hardware and bot detectionโespecially useful in high-traffic applications.
Who Benefits from UA-Extract?
This library is an ideal fit for Python developers involved in:
- Web