Python HTTP Agent Parser
Switch branches/tags
Nothing to show
Clone or download
Latest commit a990bb5 Jun 12, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
httpagentparser fixed #75 Nov 30, 2017
.gitignore Basic .gitignore Sep 5, 2012
LICENSE.txt Include LICENSE.txt in source (MIT) Sep 4, 2013
MANIFEST.in Include license in sdist Feb 2, 2018
README.md added downloads badge Jun 12, 2018
README.rst Python version support corrected May 19, 2017
dev-notes.rst Wrote usage to test using tox Jul 22, 2015
setup.py fix for #73 May 19, 2017
tests.py fixed #75 Nov 30, 2017
tox.ini Use tox to test specified Python versions. Jul 16, 2015

README.md

Downloads

Features

  • Works on Python 2.5+ and Python 3
  • Fast
  • Detects OS and Browser. Does not aim to be a full featured agent parser
  • Will not turn into django-httpagentparser ;)

Usage

>>> import httpagentparser
>>> s = "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/532.9 (KHTML, like Gecko) \
        Chrome/5.0.307.11 Safari/532.9"
>>> print httpagentparser.simple_detect(s)
('Linux', 'Chrome 5.0.307.11')
>>> print httpagentparser.detect(s)
{'os': {'name': 'Linux'},
 'browser': {'version': '5.0.307.11', 'name': 'Chrome'}}

>>> s = "Mozilla/5.0 (Linux; U; Android 2.3.5; en-in; HTC_DesireS_S510e Build/GRJ90) \
        AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
>>> print httpagentparser.simple_detect(s)
('Android Linux 2.3.5', 'Safari 4.0')
>>> print httpagentparser.detect(s)
{'dist': {'version': '2.3.5', 'name': 'Android'},
'os': {'name': 'Linux'},
'browser': {'version': '4.0', 'name': 'Safari'}}

History

http://stackoverflow.com/questions/927552/parsing-http-user-agent-string/1151956#1151956