Python port of Browserscope's user agent parser
Project description
#uap-python
A python implementation of the UA Parser (https://github.com/ua-parser, formerly https://github.com/tobie/ua-parser)
##Build Status
[![Build Status](https://travis-ci.org/ua-parser/uap-python.svg)](https://travis-ci.org/ua-parser/uap-python)
##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}
```
## Copyright
Copyright 2008 Google Inc. See ua_parser/LICENSE for more information
A python implementation of the UA Parser (https://github.com/ua-parser, formerly https://github.com/tobie/ua-parser)
##Build Status
[![Build Status](https://travis-ci.org/ua-parser/uap-python.svg)](https://travis-ci.org/ua-parser/uap-python)
##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}
```
## Copyright
Copyright 2008 Google Inc. See ua_parser/LICENSE for more information
Project details
Release history Release notifications | RSS feed
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.6.1.tar.gz
(32.5 kB
view details)
Built Distribution
File details
Details for the file ua-parser-0.6.1.tar.gz
.
File metadata
- Download URL: ua-parser-0.6.1.tar.gz
- Upload date:
- Size: 32.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a39e4e093c876b94fe2aac21bffac11130546e2c5f21f8ff342b80f2fdff3f9 |
|
MD5 | 1e220743c4483ce2af673ef44219f833 |
|
BLAKE2b-256 | 6060c88db5e4cfba563c5780de87cb82cdc9e24a56811e532e8b506e24c4fbfe |
File details
Details for the file ua_parser-0.6.1-py2.py3-none-any.whl
.
File metadata
- Download URL: ua_parser-0.6.1-py2.py3-none-any.whl
- Upload date:
- Size: 32.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 101787c472c19bac532b22e4f67d881fa411875ff437267ae07b6396b75df305 |
|
MD5 | 965aae7b7c37a2b76cbb60a884fb46db |
|
BLAKE2b-256 | 4b0a2198d95bd60fc45a22368452856cf64dbd04b4ec38600a147c3f21669f25 |