Python port of Browserscope's user agent parser
Project description
Official python implementation of the User Agent String Parser project.
Build Status
Installing
Add ua-parser[regex] to your project’s dependencies, or run
$ pip install 'ua-parser[regex]'
to install in the current environment.
ua-parser supports CPython 3.9 and newer, recent pypy (supporting 3.10), and GraalPy 24.
Quick Start
Retrieve all data on a user-agent string
>>> from ua_parser import parse
>>> 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'
>>> parse(ua_string) # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Result(user_agent=UserAgent(family='Chrome',
major='41',
minor='0',
patch='2272',
patch_minor='104'),
os=OS(family='Mac OS X',
major='10',
minor='9',
patch='4',
patch_minor=None),
device=Device(family='Mac',
brand='Apple',
model='Mac'),
string='Mozilla/5.0 (Macintosh; Intel Mac OS...
Any datum not found in the user agent string is set to None:
>>> parse("")
Result(user_agent=None, os=None, device=None, string='')
Extract only browser data from user-agent string
>>> from ua_parser import parse_user_agent
>>> 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'
>>> parse_user_agent(ua_string)
UserAgent(family='Chrome', major='41', minor='0', patch='2272', patch_minor='104')
For specific domains, a match failure just returns None:
>>> parse_user_agent("")
Extract OS information from user-agent string
>>> from ua_parser import parse_os
>>> 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'
>>> parse_os(ua_string)
OS(family='Mac OS X', major='10', minor='9', patch='4', patch_minor=None)
Extract device information from user-agent string
>>> from ua_parser import parse_device
>>> 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'
>>> parse_device(ua_string)
Device(family='Mac', brand='Apple', model='Mac')
Upgrading
Upgrading from 0.x? See the upgrade guide.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ua_parser-1.0.1.tar.gz.
File metadata
- Download URL: ua_parser-1.0.1.tar.gz
- Upload date:
- Size: 728.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9d92bf19d4329019cef91707aecc23c6d65143ad7e29a233f0580fb0d15547d
|
|
| MD5 |
256b5c489d8ee11a498295c4a487227a
|
|
| BLAKE2b-256 |
700eed98be735bc89d5040e0c60f5620d0b8c04e9e7da99ed1459e8050e90a77
|
File details
Details for the file ua_parser-1.0.1-py3-none-any.whl.
File metadata
- Download URL: ua_parser-1.0.1-py3-none-any.whl
- Upload date:
- Size: 31.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b059f2cb0935addea7e551251cbbf42e9a8872f86134163bc1a4f79e0945ffea
|
|
| MD5 |
58a375989ccb7e27d0c0ed5ac0c5728f
|
|
| BLAKE2b-256 |
9437be6dfbfa45719aa82c008fb4772cfe5c46db765a2ca4b6f524a1fdfee4d7
|