User-Agent Parser (Rust Accelerated)

0.1.5 · active · verified Fri Apr 10

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

Install

Quickstart

This quickstart demonstrates how to use the `ua-parser` library, which internally utilizes `ua-parser-rs` for accelerated user-agent string parsing when installed with the `[regex]` extra. `ua-parser-rs` itself does not expose a direct Python API for end-users.

# 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}")

view raw JSON →