Skip to main content

Python port of Browserscope's user agent parser

Project description

Official python implementation of the User Agent String Parser project.

Build Status

CI on the master branch Documentation 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


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-1.0.0a2.tar.gz (727.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ua_parser-1.0.0a2-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file ua_parser-1.0.0a2.tar.gz.

File metadata

  • Download URL: ua_parser-1.0.0a2.tar.gz
  • Upload date:
  • Size: 727.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ua_parser-1.0.0a2.tar.gz
Algorithm Hash digest
SHA256 d456831015948c8070bdd437397cc2b2501809df0389e37e3c9f7b82a7721448
MD5 5101b53d228429b97c0e71f14757c639
BLAKE2b-256 ef6e4f7401516be08a708c57709e8127ddbb17549227b1d04bdeddf14aa2985f

See more details on using hashes here.

File details

Details for the file ua_parser-1.0.0a2-py3-none-any.whl.

File metadata

  • Download URL: ua_parser-1.0.0a2-py3-none-any.whl
  • Upload date:
  • Size: 31.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ua_parser-1.0.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 3579f454fd538d3e7b4736ff5235f93a4664d7eb0ad89591080ca9e83491cd3e
MD5 5c0c331d3e4694c7ca6884211a53606f
BLAKE2b-256 da8c5394a473fd817ec93c01abe67a67de7d60a6ca38a2fe5a2591e0bc1f24be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page