Skip to main content

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

Metadata

Release files for identify-browser 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for identify-browser 1.1.0
File Size Uploaded Provenance
identify_browser-1.1.0.tar.gz 8.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for identify-browser 1.1.0
File Interpreter ABI Platform
identify_browser-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.9 kB

Release files / identify_browser-1.1.0.tar.gz

Download URL identify_browser-1.1.0.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5db412d6312a7e115d6dd1591472edf6d6e533df2e62abe24002ed31aa278259
BLAKE2b-256 checksum
How to use checksums
7d571d137b6d661fe72977c24d7c1079eec65b1dfec4abe3b4a1ae94f72c5f7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / identify_browser-1.1.0-py3-none-any.whl

Download URL identify_browser-1.1.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff2d1c82ba603677728f5e38b225fec842ee64bd99c7ee65bef214b09b9ae664
BLAKE2b-256 checksum
How to use checksums
1db396d6a065e6d89589e4028dffb6a9506b33c99da135c6df25268da4c04bb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for identify-browser 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page