A function that accepts a user agent string (and, optionally, Sec-CH-UA and Sec-CH-UA-Platform headers) and returns its best guess at the browser name, version, and platform.
Project description
A Python function that accepts a user agent string (and, optionally, Sec-CH-UA and Sec-CH-UA-Platform headers) and returns its best guess at the browser name, version, and platform.
Motivation
I wanted to be able to tell users all of the devices they were logged in on, and I wanted the information being displayed to be as accurate as possible.
While looking for a solution, I learned that using just a user agent string was not enough and neither was using just client hints.
For more information, see https://github.com/ua-parser/uap-core/issues/452
Why Is Using Just a User Agent String Not Enough?
Sometimes browsers identify themselves in their Sec-CH-UA header but not their user agent string. Brave is an example of this (except for the iOS version, which does not send Sec-CH-UA or Sec-CH-UA-Platform headers).
Why Is Using Just Client Hints Not Enough?
Sometimes browsers identify themselves in their user agent string but not their Sec-CH-UA header. The Android version of Ecosia is an example of this (its Sec-CH-UA header says that it is Chromium). In addition, some browsers do not send Sec-CH-UA or Sec-CH-UA-Platform headers.
Installation
pip install identify_browser
Usage
from identify_browser import identify_browser
# These values could come from anywhere. For example, in Django, they could come from:
#
# request.headers.get("User-Agent", "")
# request.headers.get("Sec-Ch-Ua", "")
# request.headers.get("Sec-Ch-Ua-Platform", "")
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
sec_ch_ua = '"Not/A)Brand";v="8", "Chromium";v="126", "Brave";v="126"'
sec_ch_ua_platform = '"Windows"'
browser_identity = identify_browser(user_agent, sec_ch_ua, sec_ch_ua_platform)
print(f"You appear to be using {browser_identity['name']} {browser_identity['version']} on {browser_identity['platform']}")
# Output: You appear to be using Brave 126 on Windows
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file identify_browser-1.0.0.tar.gz
.
File metadata
- Download URL: identify_browser-1.0.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e727dd7602970150062d6d29d3f9415c65cd70d11c020e2a81daebcc303e971 |
|
MD5 | 46164ce1958ef0b4e4bc32366f98186f |
|
BLAKE2b-256 | 1ae1435a3ca1364816712257f5f81f32b8c517bece2f0c9a7bddaf5fc1a5c61f |
File details
Details for the file identify_browser-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: identify_browser-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 757da2ad2490a565efd352f32f3ad1f1b276d69cc6f880700638fb7038265277 |
|
MD5 | 4bdca2f44a103c893710faffd6265ef6 |
|
BLAKE2b-256 | 22b6d47126872ce7649cb30f5f3f283f8e8a222565c8be312e6d6aff4d62ae89 |