Skip to main content

Python library to detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data

Project description

UAParser.py

fork of UAParser.js

status

Python library to detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data.

Documentation

Installation

pip install ua-parser-py

Constructor

  • UAParser([uastring])

    • returns new instance
  • UAParser.parse([uastring])

    • returns result object { 'ua': '', 'browser': {}, 'cpu': {}, 'device': {}, 'engine': {}, 'os': {} }

Properties

  • browser
    • returns { 'name': '', 'version': '' }
# Possible 'browser.name':
2345Explorer, 360 Browser, Alipay, Amaya, Android Browser, Arora, Avant, Avast, 
AVG, Baidu, Basilisk, Blazer, Bolt, Brave, Bowser, Camino, Chimera,
Chrome Headless, Chrome WebView, Chrome, Chromium, Cobalt, Comodo Dragon, Dillo,
Dolphin, Doris, DuckDuckGo, Edge, Electron, Epiphany, Facebook, Falkon, Fennec, 
Firebird, Firefox [Focus/Reality], Flock, Flow, GSA, GoBrowser, Heytap, 
Huawei Browser, iCab, ICE Browser, IE, IEMobile, IceApe, IceCat, IceDragon, 
Iceweasel, Instagram, Iridium, Iron, Jasmine, Kakao[Story/Talk], K-Meleon, 
Kindle, Klar, Klarna, Konqueror, LBBROWSER, Line, LinkedIn, Links, Lunascape, 
Lynx, MIUI Browser, Maemo, Maxthon, Midori, Minimo, Mobile Safari, Mosaic, 
Mozilla, NetFront, NetSurf, Netfront, Netscape, NokiaBrowser, Obigo, 
Oculus Browser, OmniWeb, Opera Coast, Opera [Mini/Mobi/Tablet], PaleMoon, 
PhantomJS, Phoenix, Polaris, Puffin, QQ, QQBrowser, QQBrowserLite, Quark, 
QupZilla, RockMelt, Safari, Sailfish Browser, Samsung Internet, SeaMonkey, Silk, 
Skyfire, Sleipnir, Slim, SlimBrowser, Smart Lenovo Browser, Snapchat, 
Sogou [Explorer/Mobile], Swiftfox, Tesla, TikTok, Tizen Browser, UCBrowser, 
UP.Browser, Viera, Vivaldi, Vivo Browser, Waterfox, WeChat, Weibo, Yandex, w3m, 
Whale Browser, ...

# 'browser.version' determined dynamically
  • device
    • returns { 'model': '', 'type': '', 'vendor': '' }
# Possible 'device.type':
console, mobile, tablet, smarttv, wearable, embedded

##########
# NOTE: 'desktop' is not a possible device type. 
# UAParser only reports info directly available from the UA string, which is not the case for 'desktop' device type.
# If you wish to detect desktop devices, you must handle the needed logic yourself.
# You can read more about it in this issue: https://github.com/faisalman/ua-parser-js/issues/182
##########

# Possible 'device.vendor':
Acer, Alcatel, Amazon, Apple, Archos, ASUS, AT&T, BenQ, BlackBerry, Dell,
Essential, Facebook, Fairphone, GeeksPhone, Google, HP, HTC, Huawei, Infinix, 
Jolla, Kobo, Lenovo, LG, Meizu, Microsoft, Motorola, Nexian, Nintendo, Nokia, 
Nvidia, OnePlus, OPPO, Ouya, Palm, Panasonic, Pebble, Polytron, Realme, RIM, 
Roku, Samsung, Sharp, Siemens, Sony[Ericsson], Sprint, Tecno, Tesla, Ulefone, 
Vivo, Vodafone, Xbox, Xiaomi, Zebra, ZTE, ...

# 'device.model' determined dynamically
  • engine
    • returns { 'name': '', 'version': '' }
# Possible 'engine.name'
Amaya, Blink, EdgeHTML, Flow, Gecko, Goanna, iCab, KHTML, LibWeb, Links, Lynx, 
NetFront, NetSurf, Presto, Tasman, Trident, w3m, WebKit

# 'engine.version' determined dynamically
  • os
    • returns { 'name': '', 'version': '' }
# Possible 'os.name'
AIX, Amiga OS, Android[-x86], Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
Contiki, Fedora, Firefox OS, FreeBSD, Debian, Deepin, DragonFly, elementary OS, 
Fuchsia, Gentoo, GhostBSD, GNU, Haiku, HarmonyOS, HP-UX, Hurd, iOS, Joli, KaiOS, 
Linpus, Linspire,Linux, Mac OS, Maemo, Mageia, Mandriva, Manjaro, MeeGo, Minix, 
Mint, Morph OS, NetBSD, NetRange, NetTV, Nintendo, OpenBSD, OpenVMS, OS/2, Palm, 
PC-BSD, PCLinuxOS, Plan9, PlayStation, QNX, Raspbian, RedHat, RIM Tablet OS, 
RISC OS, Sabayon, Sailfish, SerenityOS, Series40, Slackware, Solaris, SUSE, 
Symbian, Tizen, Ubuntu, Unix, VectorLinux, Viera, watchOS, WebOS, 
Windows [Phone/Mobile], Zenwalk, ...

# 'os.version' determined dynamically
  • cpu
    • returns { 'architecture': '' }
# Possible 'cpu.architecture'
68k, amd64, arm[64/hf], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, 
sparc[64]
  • ua
    • returns UA string of current instance

Usage

import json
from uaparser import UAParser

uastring1 = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2'
result = UAParser(uastring1)

print(result.browser)  # {'name': 'Chromium', 'version': '15.0.874.106', 'major': '15'}
print(result.device)  # {'vendor': None, 'model': None, 'type': None}
print(result.os)  # {'name': 'Ubuntu', 'version': '11.10'}
print(result.os['version'])  # '11.10'
print(result.engine['name'])  # 'WebKit'
print(result.cpu['architecture'])  # 'amd64'

uastring2 = 'Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)'
result = UAParser.parse(uastring2)

print(result['browser']['name'])  # 'Konqueror
print(result['os'])  # {'name': 'OpenBSD', 'version': None}
print(result['engine'])  # {'name': 'KHTML', 'version': '4.1.4'}

uastring3 = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11'
result = UAParser.parse(uastring3)

print(json.dumps(result, indent=4))
# {
#   "ua": "Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11",
#   "browser": {
#     "name": "Safari",
#     "version": "7.1.0.7",
#     "major": "7" // @deprecated
#   },
#   "cpu": {
#     "architecture": null
#   },
#   "device": {
#     "vendor": "RIM",
#     "model": "PlayBook",
#     "type": "tablet"
#   },
#   "engine": {
#     "name": "WebKit",
#     "version": "534.11"
#   },
#   "os": {
#     "name": "RIM Tablet OS",
#     "version": "1.0.0"
#   }
# }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ua-parser-py-1.0.37.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

ua_parser_py-1.0.37-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file ua-parser-py-1.0.37.tar.gz.

File metadata

  • Download URL: ua-parser-py-1.0.37.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.18 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for ua-parser-py-1.0.37.tar.gz
Algorithm Hash digest
SHA256 078eb0149d143743bd4a7a8d0e0187db6f376be0acded8d2c7bf4148185ce1ca
MD5 c1c9675c9aa7121ebbe9ae0712b53c16
BLAKE2b-256 3b67dfe240aa0ab1e444986e1cef8d304dea2cf1a8389cd04710e3d0af1deab8

See more details on using hashes here.

Provenance

File details

Details for the file ua_parser_py-1.0.37-py3-none-any.whl.

File metadata

  • Download URL: ua_parser_py-1.0.37-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.18 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for ua_parser_py-1.0.37-py3-none-any.whl
Algorithm Hash digest
SHA256 f4f0305b973785eadf7dbe5a6b5ac6c5757d53ad78e3a3b32ebbfdda47390042
MD5 c616b565d415916a61bb5dd2d352b696
BLAKE2b-256 6d9f7b8154a0bd5eacf44dd84e0cd8811bd4f26c7e49ad7695d78829a6f5288b

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page