Registry / web-framework / device-detector

device-detector

JSON →
library6.2.0pypypi✓ verified 86d ago

DeviceDetector is a precise and fast user agent parser and device detector for Python, backed by a large and frequently updated user agent database. It parses any user agent string to detect the browser, operating system, device used (desktop, tablet, mobile, TV, etc.), brand, and model. Optimized for speed through efficient code and in-memory caching, the library is currently at version 6.2.0 and maintains an active release cadence, primarily updating to incorporate upstream detection rules from the Matomo project.

pip install device_detector
INSTALL
IMPORT
SIG · DEVICE-DETECTOR
D
device-detector
web-frameworkpythonv6.2.0
Install
3.2s avg
Import
463ms
Disk
43MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v6.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.915 runs
build_error
glibc
py 3.103.915 runs
installs and imports cleanly · install 3.2s · import 0.370s · 45MB
43MB installed
● package 43MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DeviceDetector
from device_detector import DeviceDetector

Initializes `DeviceDetector` with a user agent string, parses it, and demonstrates how to access various detected properties like OS, device type, brand, and browser.

from device_detector import DeviceDetector # Example User Agent string ua = 'Mozilla/5.0 (Linux; Android 4.3; C5502 Build/10.4.1.B.0.101) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Mobile Safari/537.36' # Initialize and parse the User Agent device = DeviceDetector(ua).parse() # Access detected information print(f"Is bot: {device.is_bot()}") print(f"OS name: {device.os_name()}") print(f"OS version: {device.os_version()}") print(f"Device type: {device.device_type()}") print(f"Device brand: {device.device_brand()}") print(f"Device model: {device.device_model()}") print(f"Browser name: {device.client_name()}") print(f"Browser version: {device.client_version()}")
Debug
Known issues
gotchaThe Python port is not an exact 1:1 replica of the original PHP Device Detector library; some Pythonic adaptations were made. Users migrating from or comparing against the PHP version might encounter minor behavioral differences.
fix
Consult the Python library's documentation and examples for specific method names and return types.
affects: All versions
gotchaFor optimal performance, especially when processing a large volume of user agents, it is recommended to install `pyyaml` (configured with `libyaml` for `CSafeLoader`) and the `mrab` regex module. Without these, the library will still function but may be slower.
fix
Install `pyyaml` (with C extension support) and `mrab`: `pip install pyyaml mrab`.
affects: All versions
gotchaThe detection logic primarily relies on regex YAML files sourced from the upstream Matomo/PHP Device Detector project. While this ensures up-to-date detection rules, major changes or specific user-agent handling updates in the upstream project will directly reflect in this Python port upon its next release incorporating those changes.
fix
Keep the library updated to benefit from the latest upstream detection rules. Monitor upstream project changes for potential impacts.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'device_detector'
The 'device-detector' package has not been installed in the current Python environment.
fix
Install the library using pip: `pip install device_detector`
AttributeError: 'DeviceDetector' object has no attribute 'is_bot'
Attempted to access detection methods (e.g., `is_bot()`, `os_name()`) before calling the `parse()` method on the `DeviceDetector` instance. The object needs to process the user agent string first.
fix
Ensure that `device_detector_instance.parse()` is called before accessing any detection results. Example: `device = DeviceDetector(ua).parse()`.
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x__ in position __: invalid start byte
The user agent string provided contains non-UTF-8 encoded characters that the Python interpreter or the library's internal processing cannot handle by default.
fix
Ensure the user agent string is correctly encoded. If the origin encoding is known (e.g., 'latin-1', 'windows-1252'), decode it before passing to DeviceDetector, or try to sanitize problematic characters if encoding is unknown.
Upgrade
Version history
6.2.0latest on PyPI · released Mar 10, 2026
Audit
Dependencies
pyyamloptionalUsed for CSafeLoader, which offers performance benefits if configured with libyaml.
mraboptionalThe 'mrab' regex module is preferred for faster performance if installed.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
2
Resources
device-detector — pip install device-detector · libregistry