Skip to main content

Library for user agent parsing

Project description

ua-parse PyPI version

User-agent parsing library inspired by the https://faisalman.github.io/ua-parser-js/ project.

It is essentially an adaptation of ua-parser-js in python. Unlike other UA-parsing libraries, this library detect MacOS as Mac OS, not Mac OS X, and the browser, engine, and os versions are already joined into a one string, which is convenient for use.

Installation

pip install ua-parse

Get started

The library exports just one function that returns all the parameters at once.

Parse user-agent:

from ua_parse import parse_ua

safari_user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15'
result = parse_ua(safari_user_agent)

assert result == {
    'browser': {'name': 'Safari', 'version': '15.2'},
    'cpu': {'architecture': None},
    'device': {'model': None, 'type': None, 'vendor': None},
    'engine': {'name': 'WebKit', 'version': '605.1.15'},
    'os': {'name': 'Mac OS', 'version': '10.15.7'},
}


ie_user_agent = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko'
result_2 = parse_ua(ie_user_agent)

assert result_2 == {
    'browser': {'name': 'IE', 'version': '11.0'},
    'cpu': {'architecture': None},
    'device': {'model': None, 'type': None, 'vendor': None},
    'engine': {'name': 'Trident', 'version': '7.0'},
    'os': {'name': 'Windows', 'version': '8.1'},
}



empty_user_agent = ''
result_3 = parse_ua(empty_user_agent)

assert result_3 == {
    'browser': {'name': None, 'version': None},
    'cpu': {'architecture': None},
    'device': {'model': None, 'type': None, 'vendor': None},
    'engine': {'name': None, 'version': None},
    'os': {'name': None, 'version': None},
}

Supported OS:

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, HP-UX, Hurd, iOS, Joli, KaiOS, Linpus, Linspire,
Linux, Mac OS, Maemo, Mageia, Mandriva, Manjaro, MeeGo, Minix, Mint, Morph OS, NetBSD,
Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD, PCLinuxOS, Plan9, PlayStation, QNX,
Raspbian, RedHat, RIM Tablet OS, RISC OS, Sabayon, Sailfish, Series40, Slackware, Solaris,
SUSE, Symbian, Tizen, Ubuntu, Unix, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...

Supported browsers:

2345Explorer, 360 Browser, Amaya, Android Browser, Arora, Avant, Avast, AVG,
BIDUBrowser, Baidu, Basilisk, Blazer, Bolt, Brave, Bowser, Camino, Chimera,
Chrome Headless, Chrome WebView, Chrome, Chromium, Comodo Dragon, Dillo,
Dolphin, Doris, Edge, Electron, Epiphany, Facebook, Falkon, Fennec, Firebird,
Firefox [Reality], Flock, Flow, GSA, GoBrowser, ICE Browser, IE, IEMobile, IceApe,
IceCat, IceDragon, Iceweasel, Instagram, Iridium, Iron, Jasmine, K-Meleon,
Kindle, Klar, Konqueror, LBBROWSER, Line, Links, Lunascape, Lynx, MIUI Browser,
Maemo Browser, Maemo, Maxthon, MetaSr 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 Browser, SeaMonkey, Silk, Skyfire, Sleipnir, Slim,
SlimBrowser, Swiftfox, Tesla, Tizen Browser, UCBrowser, UP.Browser, Vivaldi,
Waterfox, WeChat, Weibo, Yandex, baidu, iCab, w3m, Whale Browser...

Supported device types and vendors:

console, mobile, tablet, smarttv, wearable, embedded
Acer, Alcatel, Amazon, Apple, Archos, ASUS, AT&T, BenQ, BlackBerry, Dell,
Essential, Fairphone, GeeksPhone, Google, HP, HTC, Huawei, Jolla, 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, Tesla, Vivo, Vodafone, Xbox, Xiaomi, Zebra, ZTE, ...

Supported engines:

Amaya, Blink, EdgeHTML, Flow, Gecko, Goanna, iCab, KHTML, Links, Lynx, NetFront,
NetSurf, Presto, Tasman, Trident, w3m, WebKit

Supported cpus:

68k, amd64, arm[64/hf], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]

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-parse-1.0.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ua_parse-1.0.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file ua-parse-1.0.1.tar.gz.

File metadata

  • Download URL: ua-parse-1.0.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for ua-parse-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ec6c34368fdc52e99ee647d11220f0dd559b04f2b5f82d078fe47133da447d1a
MD5 e85f354323d6ea1fb844947cd8b0b14c
BLAKE2b-256 f8941d5440eeaf9df44d2ebcafdf27c0472c99ae8d2248c11b6029b4532b3db0

See more details on using hashes here.

File details

Details for the file ua_parse-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: ua_parse-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for ua_parse-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0448ea4026e549bef286f933f35d67e6d59a52c91f5b440b3ee1a2f4448a18c6
MD5 8431eb8f2d0db38636fd4ef9d97dc6bd
BLAKE2b-256 e65649cebada3d985c49f2af7fbee58eb4f2c738d3307cb441a9249cd940f12c

See more details on using hashes here.

Supported by

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