Skip to content


Subversion checkout URL

You can clone with
Download ZIP


iPad and Android phone/tablet detection #17

merged 12 commits into from

3 participants


Added detection for iPad and Android phone/tablet.


Thanks, I've fixed and added the unit tests appropriately, so it should be fine now.


I've also added Blackberry phone and tablet detection, as well as unit tests for those. Sorry for all these commits coming in at once.

@shon shon merged commit 9b10fba into shon:master

Hi Srs81/Suman,

I realized that we have "Phone" or "Tablet" in version now. For example for my phone running Android 2.3.5, version is detected as "Phone 2.3.5". I am not fully convinced by this. My opinion is Android version should always show up as 2.3.5 we should not include device type if it is not present in the version. I am reverting back deviceType detection code. Let me know if you don't agree.

Further, I think if you still need device type, we may have a new key "device_type" in detect result. One of us will have to add code accordingly. But we will delay documenting this device type detection.



Hi, makes sense. For my use, I actually do need to differentiate phone from tablet (and connected devices like Playstation, Google TV, etc), and that's why I added that code in, but maybe there are better ways to handle that. I'm open to whatever solution you come up with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 29, 2012
  1. @srs81

    iPad detection

    srs81 authored
    Added iPad detection (mimicking iPhone detection)
  2. @srs81

    Android phone / tablet differentiation

    srs81 authored
    Added a check to differentiate between Android phones and tablets.
  3. @srs81
  4. @srs81

    Fixed Android phone unit test

    srs81 authored
  5. @srs81 @sumanlongtail

    iPad detection

    srs81 authored sumanlongtail committed
    Added iPad detection (mimicking iPhone detection)
  6. @srs81 @sumanlongtail

    Android phone / tablet differentiation

    srs81 authored sumanlongtail committed
    Added a check to differentiate between Android phones and tablets.
  7. @srs81 @sumanlongtail

    Unit tests for iPad and Android tablets

    srs81 authored sumanlongtail committed
  8. @srs81 @sumanlongtail

    Fixed Android phone unit test

    srs81 authored sumanlongtail committed
  9. @srs81

    Fixed Windows unit test

    srs81 authored
  10. @sumanlongtail
  11. @sumanlongtail
  12. @srs81

    Blackberry Tests added

    srs81 authored
    Added unit tests for Blackberry devices
This page is out of date. Refresh to see the latest.
Showing with 39 additions and 4 deletions.
  1. +39 −4 httpagentparser/
43 httpagentparser/
@@ -172,6 +172,14 @@ class Linux(OS):
def getVersion(self, agent): pass
+class Blackberry(OS):
+ look_for = 'BlackBerry'
+ prefs = dict(dist=["BlackberryPlaybook"], flavor=None)
+ def getVersion(self, agent): pass
+class BlackberryPlaybook(Dist):
+ look_for = 'PlayBook'
+ def getVersion(self, agent): pass
class Macintosh(OS):
look_for = 'Macintosh'
@@ -242,8 +250,13 @@ class Android(Dist):
look_for = 'Android'
def getVersion(self, agent):
- return agent.split('Android')[-1].split(';')[0].strip()
+ if "Mobile Safari" in agent:
+ deviceType = "Phone"
+ else:
+ deviceType = "Tablet"
+ aVersion = agent.split('Android')[-1].split(';')[0].strip()
+ return deviceType + " " + aVersion
class WebOS(Dist):
look_for = 'hpwOS'
@@ -262,6 +275,16 @@ def getVersion(self, agent):
version = part.split(c)[0]
return version.replace('_', '.')
+class IPad(Dist):
+ look_for = 'iPad'
+ def getVersion(self, agent):
+ version_end_chars = [';', ')']
+ part = agent.split('Mac OS')[-1].strip()
+ for c in version_end_chars:
+ if c in part:
+ version = part.split(c)[0]
+ return version.replace('_', '.')
detectorshub = DetectorsHub()
@@ -343,8 +366,8 @@ def simple_detect(agent):
('Ubuntu Linux 10.04', 'Firefox 3.6'),
{'dist': {'version': '10.04', 'name': 'Ubuntu'}, 'os': {'name': 'Linux'}, 'browser': {'version': '3.6', 'name': 'Firefox'}},),
("Mozilla/5.0 (Linux; U; Android 2.2.1; fr-ch; A43 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
- ('Android Linux 2.2.1', 'Safari 4.0'),
- {'dist': {'version': '2.2.1', 'name': 'Android'}, 'os': {'name': 'Linux'}, 'browser': {'version': '4.0', 'name': 'Safari'}},),
+ ('Android Linux Phone 2.2.1', 'Safari 4.0'),
+ {'dist': {'version': 'Phone 2.2.1', 'name': 'Android'}, 'os': {'name': 'Linux'}, 'browser': {'version': '4.0', 'name': 'Safari'}},),
("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3",
('MacOS IPhone X', 'Safari 3.0'),
{'flavor': {'version': 'X', 'name': 'MacOS'}, 'dist': {'version': 'X', 'name': 'IPhone'}, 'browser': {'version': '3.0', 'name': 'Safari'}},),
@@ -363,6 +386,18 @@ def simple_detect(agent):
("Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.2; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.40.1 Safari/534.6 TouchPad/1.0",
("WebOS Linux 3.0.2", "WOSBrowser"),
{'dist': {'name': 'WebOS', 'version': '3.0.2'}, 'os' : {'name' : 'Linux'}, 'browser': {'name': 'WOSBrowser'}},),
+("Mozilla/5.0 (iPad; CPU OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3",
+ ('MacOS IPad X', 'Safari 5.1'),
+ {'flavor': {'version': 'X', 'name': 'MacOS'}, 'dist': {'version': 'X', 'name': 'IPad'}, 'browser': {'version': '5.1', 'name': 'Safari'}},),
+("Mozilla/5.0 (Linux; U; Android 3.2.1; en-gb; Transformer TF101 Build/HTK75) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13",
+ ('Android Linux Tablet 3.2.1', 'Safari 4.0'),
+ {'dist': {'version': 'Tablet 3.2.1', 'name': 'Android'}, 'os': {'name': 'Linux'}, 'browser': {'version': '4.0', 'name': 'Safari'}},),
+("Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; en-US) AppleWebKit/534.8+ (KHTML, like Gecko) Version/ Mobile Safari/534.8+",
+ ('Blackberry', 'Safari'),
+ {'os': {'name': 'Blackberry'}, 'browser': {'version': '', 'name': 'Safari'}},),
+("Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/ Safari/534.11+",
+ ('BlackberryPlaybook', 'Safari'),
+ {'dist': {'name': 'BlackberryPlaybook'}, 'browser': {'version': '', 'name': 'Safari'}},),
class TestHAP(unittest.TestCase):
Something went wrong with that request. Please try again.