User-Agent Parser (Rust Accelerated)
ua-parser-rs is a Python package that provides a native Rust accelerator for user-agent string parsing. It is not intended for direct use, but rather serves as a high-performance backend for the `ua-parser` Python library. Currently at version 0.1.5, its releases are tied to the upstream `uap-rust` project, with semi-regular updates reflecting performance improvements and bug fixes in the core Rust library.
Warnings
- breaking Version 0.1.4 (and subsequent versions) removed support for Python versions older than 3.10. This is due to the adoption of abi3-py310 wheels and the end-of-life status of Python 3.9 and PyPy 3.10.
- gotcha The `ua-parser-rs` package is designed as a native accelerator and is not intended for direct use. It provides the Rust backend for the `ua-parser` Python library. Its API is considered simplistic and lacks formal stability guarantees for direct consumer use.
Install
-
pip install ua-parser-rs -
pip install 'ua-parser[regex]'
Quickstart
# ua-parser-rs is primarily an accelerator for the 'ua-parser' library.
# Direct import of ua_parser_rs is not typically done or recommended.
# To leverage the Rust acceleration, use the 'ua-parser' library:
# Ensure 'ua-parser[regex]' is installed to utilize the Rust backend
# pip install 'ua-parser[regex]'
from ua_parser import parse
ua_string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36'
result = parse(ua_string)
print(f"Browser: {result.user_agent.family} {result.user_agent.major}.{result.user_agent.minor}")
print(f"OS: {result.os.family} {result.os.major}.{result.os.minor}")
print(f"Device: {result.device.family}")