Skip to main content

Python port of Browserscope's user agent parser

Project description

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

Build Status

https://travis-ci.org/ua-parser/uap-python.svg

Installing

Install via pip

Just run:

$ pip install ua-parser

Manual install

In the top-level directory run:

$ python setup.py install

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': None, 'family': 'Other', 'model': None},
    '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'}

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': None,
    'family': 'Other',
    'model': None}

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-0.7.1.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

ua_parser-0.7.1-py2.py3-none-any.whl (32.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ua-parser-0.7.1.tar.gz.

File metadata

  • Download URL: ua-parser-0.7.1.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ua-parser-0.7.1.tar.gz
Algorithm Hash digest
SHA256 e1f7cb16ccb68d6c93b19348e678500bec8cd1f692e49214dd38ca2d100ada9b
MD5 ded91d12aa2e0672db397590d0f649e6
BLAKE2b-256 9cf4872c229b0d6335bc56d552bceebc91dae2f5d3abf2e0e749db32b765471b

See more details on using hashes here.

File details

Details for the file ua_parser-0.7.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for ua_parser-0.7.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b6dc4f1f7f7a6be54efaeac91dbbda5133ac611eea25df44ffb3b2b3af82b736
MD5 466d2cb6986d21f7f6885d286391c986
BLAKE2b-256 687a785386e8787608aa00f300b15db4c54685eaaf8e97a8692fcb7f555be190

See more details on using hashes here.

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