|
| 1 | +uap-python |
| 2 | +========== |
| 3 | + |
| 4 | +A python implementation of the UA Parser (https://github.com/ua-parser, |
| 5 | +formerly https://github.com/tobie/ua-parser) |
| 6 | + |
| 7 | +Build Status |
| 8 | +------------ |
| 9 | + |
| 10 | +.. image:: https://travis-ci.org/ua-parser/uap-python.svg |
| 11 | + :target: https://travis-ci.org/ua-parser/uap-python |
| 12 | + |
| 13 | +Installing |
| 14 | +---------- |
| 15 | + |
| 16 | +Install via pip |
| 17 | +~~~~~~~~~~~~~~~ |
| 18 | + |
| 19 | +Just run: |
| 20 | + |
| 21 | +.. code-block:: sh |
| 22 | +
|
| 23 | + $ pip install ua-parser |
| 24 | +
|
| 25 | +Manual install |
| 26 | +~~~~~~~~~~~~~~ |
| 27 | + |
| 28 | +In the top-level directory run: |
| 29 | + |
| 30 | +.. code-block:: sh |
| 31 | +
|
| 32 | + $ python setup.py install |
| 33 | +
|
| 34 | +Getting Started |
| 35 | +--------------- |
| 36 | + |
| 37 | +Retrieve data on a user-agent string |
| 38 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 39 | + |
| 40 | +.. code-block:: python |
| 41 | +
|
| 42 | + >>> from ua_parser import user_agent_parser |
| 43 | + >>> import pprint |
| 44 | + >>> pp = pprint.PrettyPrinter(indent=4) |
| 45 | + >>> 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' |
| 46 | + >>> parsed_string = user_agent_parser.Parse(ua_string) |
| 47 | + >>> pp.pprint(parsed_string) |
| 48 | + { 'device': { 'brand': None, 'family': 'Other', 'model': None}, |
| 49 | + 'os': { 'family': 'Mac OS X', |
| 50 | + 'major': '10', |
| 51 | + 'minor': '9', |
| 52 | + 'patch': '4', |
| 53 | + 'patch_minor': None}, |
| 54 | + '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', |
| 55 | + 'user_agent': { 'family': 'Chrome', |
| 56 | + 'major': '41', |
| 57 | + 'minor': '0', |
| 58 | + 'patch': '2272'}} |
| 59 | +
|
| 60 | +Extract browser data from user-agent string |
| 61 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 62 | + |
| 63 | +.. code-block:: python |
| 64 | +
|
| 65 | + >>> from ua_parser import user_agent_parser |
| 66 | + >>> import pprint |
| 67 | + >>> pp = pprint.PrettyPrinter(indent=4) |
| 68 | + >>> 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' |
| 69 | + >>> parsed_string = user_agent_parser.ParseUserAgent(ua_string) |
| 70 | + >>> pp.pprint(parsed_string) |
| 71 | + { 'family': 'Chrome', |
| 72 | + 'major': '41', |
| 73 | + 'minor': '0', |
| 74 | + 'patch': '2272'} |
| 75 | +
|
| 76 | +Extract OS information from user-agent string |
| 77 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 78 | + |
| 79 | +.. code-block:: python |
| 80 | +
|
| 81 | + >>> from ua_parser import user_agent_parser |
| 82 | + >>> import pprint |
| 83 | + >>> pp = pprint.PrettyPrinter(indent=4) |
| 84 | + >>> 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' |
| 85 | + >>> parsed_string = user_agent_parser.ParseOS(ua_string) |
| 86 | + >>> pp.pprint(parsed_string) |
| 87 | + { 'family': 'Mac OS X', |
| 88 | + 'major': '10', |
| 89 | + 'minor': '9', |
| 90 | + 'patch': '4', |
| 91 | + 'patch_minor': None} |
| 92 | +
|
| 93 | +Extract Device information from user-agent string |
| 94 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 95 | + |
| 96 | +.. code-block:: python |
| 97 | +
|
| 98 | + >>> from ua_parser import user_agent_parser |
| 99 | + >>> import pprint |
| 100 | + >>> pp = pprint.PrettyPrinter(indent=4) |
| 101 | + >>> 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' |
| 102 | + >>> parsed_string = user_agent_parser.ParseDevice(ua_string) |
| 103 | + >>> pp.pprint(parsed_string) |
| 104 | + { 'brand': None, |
| 105 | + 'family': 'Other', |
| 106 | + 'model': None} |
| 107 | +
|
| 108 | +Copyright |
| 109 | +--------- |
| 110 | + |
| 111 | +Copyright 2008 Google Inc. See ua\_parser/LICENSE for more information |
0 commit comments