Python port of Browserscope's user agent parser
Project Links
Meta
Author: Stephen Lamm, PBS, Selwin Ong, Matt Robenolt, Lindsey Simon
Maintainer: masklinn
Requires Python: >=3.9
Classifiers
Development Status
- 5 - Production/Stable
Environment
- Web Environment
Intended Audience
- Developers
Operating System
- OS Independent
License
- OSI Approved :: Apache Software License
Programming Language
- Python
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
Topic
- Internet :: WWW/HTTP
- Software Development :: Libraries :: Python Modules
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.
Feb 01, 2025
1.0.1
Nov 28, 2024
1.0.0
Nov 26, 2024
1.0.0a2
Nov 26, 2024
1.0.0a1
Jul 08, 2023
0.18.0
Aug 27, 2022
0.16.1
Aug 21, 2022
0.16.0
Aug 27, 2022
0.15.2
Aug 20, 2022
0.15.1
Jun 28, 2022
0.15.0
Feb 27, 2020
0.10.0
Feb 04, 2020
0.9.0
Apr 09, 2018
0.8.0
Feb 02, 2017
0.7.3
Oct 31, 2016
0.7.2
May 01, 2016
0.7.1
Mar 18, 2016
0.7.0
Dec 22, 2015
0.6.1
Nov 11, 2015
0.5.1
Oct 14, 2015
0.5.0
Sep 05, 2015
0.4.1
Sep 04, 2015
0.4.0
Nov 28, 2014
0.3.6
Mar 07, 2014
0.3.5
Aug 02, 2013
0.3.4
Jul 09, 2013
0.3.3
Jan 11, 2013
0.3.2
Jan 05, 2013
0.3.1
Dec 29, 2012
0.3.0