Skip to main content

Python port of Browserscope's user agent parser that is kept up to date!

Project description

An up to date python implementation of the UA Parser (https://github.com/ua-parser, formerly https://github.com/tobie/ua-parser)

Build Status

CI on the master branch

Installing

Install via pip

Just run:

$ pip install ua-parser-up2date

Manual install

In the top-level directory run:

$ python setup.py install

Change Log

Because this repo is mostly a python wrapper for the User Agent String Parser repo (https://github.com/ua-parser/uap-core), the changes made to this repo are best described by the update diffs in that project. Please see the diffs for this submodule (https://github.com/ua-parser/uap-core/releases) for a list of what has changed between versions of this package.

Getting Started

Retrieve data on a user-agent string

>>> from ua_parser import user_agent_parser
>>> import pprint
>>> pp = pprint.PrettyPrinter(indent=4)
>>> ua_string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36'
>>> parsed_string = user_agent_parser.Parse(ua_string)
>>> pp.pprint(parsed_string)
{   'device': {'brand': 'Apple', 'family': 'Mac', 'model': 'Mac'},
    'os': {   'family': 'Mac OS X',
              'major': '10',
              'minor': '9',
              'patch': '4',
              'patch_minor': None},
    'string': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) '
              'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 '
              'Safari/537.36',
    'user_agent': {   'family': 'Chrome',
                      'major': '41',
                      'minor': '0',
                      'patch': '2272'}}

Extract browser data from user-agent string

>>> from ua_parser import user_agent_parser
>>> import pprint
>>> pp = pprint.PrettyPrinter(indent=4)
>>> ua_string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36'
>>> parsed_string = user_agent_parser.ParseUserAgent(ua_string)
>>> pp.pprint(parsed_string)
{'family': 'Chrome', 'major': '41', 'minor': '0', 'patch': '2272'}

⚠️Before 0.15, the convenience parsers (ParseUserAgent, ParseOs, and ParseDevice) were not cached, which could result in degraded performances when parsing large amounts of identical user-agents (which might occur for real-world datasets).

For these versions (up to 0.10 included), prefer using Parse and extracting the sub-component you need from the resulting dictionary.

Extract OS information from user-agent string

>>> from ua_parser import user_agent_parser
>>> import pprint
>>> pp = pprint.PrettyPrinter(indent=4)
>>> ua_string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36'
>>> parsed_string = user_agent_parser.ParseOS(ua_string)
>>> pp.pprint(parsed_string)
{   'family': 'Mac OS X',
    'major': '10',
    'minor': '9',
    'patch': '4',
    'patch_minor': None}

Extract Device information from user-agent string

>>> from ua_parser import user_agent_parser
>>> import pprint
>>> pp = pprint.PrettyPrinter(indent=4)
>>> ua_string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36'
>>> parsed_string = user_agent_parser.ParseDevice(ua_string)
>>> pp.pprint(parsed_string)
{'brand': 'Apple', 'family': 'Mac', 'model': 'Mac'}

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-up2date-0.16.1.tar.gz (41.8 kB view details)

Uploaded Source

File details

Details for the file ua-parser-up2date-0.16.1.tar.gz.

File metadata

  • Download URL: ua-parser-up2date-0.16.1.tar.gz
  • Upload date:
  • Size: 41.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for ua-parser-up2date-0.16.1.tar.gz
Algorithm Hash digest
SHA256 8f3fc1b2de17c06ca0e97ea536af8accf60661a7ec333fa25a7fe45647e5ccee
MD5 b3fe75898cb9af0bc06181ba9df884a9
BLAKE2b-256 80887eaf7c2e99c0b7d137d5705f8512390897cfe4a8cdaab6ce16d81c4d9e13

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