METADATA 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. Metadata-Version: 2.0
  2. Name: user-agents
  3. Version: 1.1.0
  4. Summary: A library to identify devices (phones, tablets) and their capabilities by parsing (browser/HTTP) user agent strings
  5. Home-page: https://github.com/selwin/python-user-agents
  6. Author: Selwin Ong
  7. Author-email: selwin.ong@gmail.com
  8. License: MIT
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 5 - Production/Stable
  11. Classifier: Environment :: Web Environment
  12. Classifier: Intended Audience :: Developers
  13. Classifier: License :: OSI Approved :: MIT License
  14. Classifier: Operating System :: OS Independent
  15. Classifier: Programming Language :: Python
  16. Classifier: Programming Language :: Python :: 2
  17. Classifier: Programming Language :: Python :: 2.7
  18. Classifier: Programming Language :: Python :: 3
  19. Classifier: Programming Language :: Python :: 3.3
  20. Classifier: Programming Language :: Python :: 3.4
  21. Classifier: Topic :: Internet :: WWW/HTTP
  22. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  23. Requires-Dist: ua-parser (>=0.4.1)
  24. Python User Agents
  25. ==================
  26. ``user_agents`` is a Python library that provides an easy way to
  27. identify/detect devices like mobile phones, tablets and their
  28. capabilities by parsing (browser/HTTP) user agent strings. The goal is
  29. to reliably detect whether:
  30. - User agent is a mobile, tablet or PC based device
  31. - User agent has touch capabilities (has touch screen)
  32. ``user_agents`` relies on the excellent
  33. ``ua-parser <https://github.com/tobie/ua-parser>``\ \_ to do the actual
  34. parsing of the raw user agent string.
  35. Installation
  36. ------------
  37. .. figure:: https://secure.travis-ci.org/selwin/python-user-agents.png
  38. :alt: Build status
  39. Build status
  40. ``user-agents`` is hosted on
  41. `PyPI <http://pypi.python.org/pypi/user-agents/>`__ and can be installed
  42. as such:
  43. ::
  44. pip install pyyaml ua-parser user-agents
  45. Alternatively, you can also get the latest source code from
  46. ``Github``\ \_ and install it manually.
  47. Usage
  48. -----
  49. Various basic information that can help you identify visitors can be
  50. accessed ``browser``, ``device`` and ``os`` attributes. For example:
  51. .. code:: python
  52. from user_agents import parse
  53. # iPhone's user agent string
  54. ua_string = 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3'
  55. user_agent = parse(ua_string)
  56. # Accessing user agent's browser attributes
  57. user_agent.browser # returns Browser(family=u'Mobile Safari', version=(5, 1), version_string='5.1')
  58. user_agent.browser.family # returns 'Mobile Safari'
  59. user_agent.browser.version # returns (5, 1)
  60. user_agent.browser.version_string # returns '5.1'
  61. # Accessing user agent's operating system properties
  62. user_agent.os # returns OperatingSystem(family=u'iOS', version=(5, 1), version_string='5.1')
  63. user_agent.os.family # returns 'iOS'
  64. user_agent.os.version # returns (5, 1)
  65. user_agent.os.version_string # returns '5.1'
  66. # Accessing user agent's device properties
  67. user_agent.device # returns Device(family=u'iPhone', brand=u'Apple', model=u'iPhone')
  68. user_agent.device.family # returns 'iPhone'
  69. user_agent.device.brand # returns 'Apple'
  70. user_agent.device.model # returns 'iPhone'
  71. # Viewing a pretty string version
  72. str(user_agent) # returns "iPhone / iOS 5.1 / Mobile Safari 5.1"
  73. ``user_agents`` also expose a few other more "sophisticated" attributes
  74. that are derived from one or more basic attributes defined above. As for
  75. now, these attributes should correctly identify popular
  76. platforms/devices, pull requests to support smaller ones are always
  77. welcome.
  78. Currently these attributes are supported:
  79. - ``is_mobile``: whether user agent is identified as a mobile phone
  80. (iPhone, Android phones, Blackberry, Windows Phone devices etc)
  81. - ``is_tablet``: whether user agent is identified as a tablet device
  82. (iPad, Kindle Fire, Nexus 7 etc)
  83. - ``is_pc``: whether user agent is identified to be running a
  84. traditional "desktop" OS (Windows, OS X, Linux)
  85. - ``is_touch_capable``: whether user agent has touch capabilities
  86. - ``is_bot``: whether user agent is a search engine crawler/spider
  87. For example:
  88. .. code:: python
  89. from user_agents import parse
  90. # Let's start from an old, non touch Blackberry device
  91. ua_string = 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/331 UNTRUSTED/1.0 3gpp-gba'
  92. user_agent = parse(ua_string)
  93. user_agent.is_mobile # returns True
  94. user_agent.is_tablet # returns False
  95. user_agent.is_touch_capable # returns False
  96. user_agent.is_pc # returns False
  97. user_agent.is_bot # returns False
  98. str(user_agent) # returns "BlackBerry 9700 / BlackBerry OS 5 / BlackBerry 9700"
  99. # Now a Samsung Galaxy S3
  100. ua_string = 'Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
  101. user_agent = parse(ua_string)
  102. user_agent.is_mobile # returns True
  103. user_agent.is_tablet # returns False
  104. user_agent.is_touch_capable # returns True
  105. user_agent.is_pc # returns False
  106. user_agent.is_bot # returns False
  107. str(user_agent) # returns "Samsung GT-I9300 / Android 4.0.4 / Android 4.0.4"
  108. # iPad's user agent string
  109. ua_string = 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10'
  110. user_agent = parse(ua_string)
  111. user_agent.is_mobile # returns False
  112. user_agent.is_tablet # returns True
  113. user_agent.is_touch_capable # returns True
  114. user_agent.is_pc # returns False
  115. user_agent.is_bot # returns False
  116. str(user_agent) # returns "iPad / iOS 3.2 / Mobile Safari 4.0.4"
  117. # Kindle Fire's user agent string
  118. ua_string = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true'
  119. user_agent = parse(ua_string)
  120. user_agent.is_mobile # returns False
  121. user_agent.is_tablet # returns True
  122. user_agent.is_touch_capable # returns True
  123. user_agent.is_pc # returns False
  124. user_agent.is_bot # returns False
  125. str(user_agent) # returns "Kindle / Android / Amazon Silk 1.1.0-80"
  126. # Touch capable Windows 8 device
  127. ua_string = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)'
  128. user_agent = parse(ua_string)
  129. user_agent.is_mobile # returns False
  130. user_agent.is_tablet # returns False
  131. user_agent.is_touch_capable # returns True
  132. user_agent.is_pc # returns True
  133. user_agent.is_bot # returns False
  134. str(user_agent) # returns "PC / Windows 8 / IE 10"
  135. Running Tests
  136. -------------
  137. ::
  138. python -m unittest discover
  139. Changelog
  140. ---------
  141. Version 1.1.0
  142. ~~~~~~~~~~~~~
  143. - Better FirefoxOS and ChromeBook detection
  144. - Fixes browser version number parsing.
  145. Version 1.0.0
  146. ~~~~~~~~~~~~~
  147. - Fixes packaging issue
  148. Version 1.0
  149. ~~~~~~~~~~~
  150. - Adds compatibility with ``ua-parser`` 0.4.0
  151. - Access to more device information in ``user_agent.device.brand`` and
  152. ``user_agent.device.model``
  153. ===
  154. Version 0.3.2
  155. ~~~~~~~~~~~~~
  156. - Better mobile detection
  157. - Better PC detection
  158. Version 0.3.1
  159. ~~~~~~~~~~~~~
  160. - user\_agent.is\_mobile returns True when mobile spider is detected
  161. Version 0.3.0
  162. ~~~~~~~~~~~~~
  163. - Added **str**/**unicode** methods for convenience of pretty string
  164. Version 0.2.0
  165. ~~~~~~~~~~~~~
  166. - Fixed errors when running against newer versions if ua-parser
  167. - Support for Python 3
  168. Version 0.1.1
  169. ~~~~~~~~~~~~~
  170. - Added ``is_bot`` property
  171. - Symbian OS devices are now detected as a mobile device
  172. Version 0.1
  173. ~~~~~~~~~~~
  174. - Initial release
  175. Developed by the cool guys at `Stamps <http://stamps.co.id>`__.