Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
1Metadata-Version: 2.12Name: user-agents3Version: 2.2.04Summary: A library to identify devices (phones, tablets) and their capabilities by parsing browser user agent strings.5Home-page: https://github.com/selwin/python-user-agents6Author: Selwin Ong7Author-email: selwin.ong@gmail.com8License: MIT9Platform: UNKNOWN10Classifier: Development Status :: 5 - Production/Stable11Classifier: Environment :: Web Environment12Classifier: Intended Audience :: Developers13Classifier: License :: OSI Approved :: MIT License14Classifier: Operating System :: OS Independent15Classifier: Programming Language :: Python16Classifier: Programming Language :: Python :: 217Classifier: Programming Language :: Python :: 2.718Classifier: Programming Language :: Python :: 319Classifier: Programming Language :: Python :: 3.420Classifier: Programming Language :: Python :: 3.521Classifier: Programming Language :: Python :: 3.622Classifier: Programming Language :: Python :: 3.723Classifier: Programming Language :: Python :: 3.824Classifier: Topic :: Internet :: WWW/HTTP25Classifier: Topic :: Software Development :: Libraries :: Python Modules26Description-Content-Type: text/markdown27Requires-Dist: ua-parser (>=0.10.0)28 29Python User Agents30==================31 32`user_agents` is a Python library that provides an easy way to identify/detect devices like mobile phones, tablets and their capabilities by parsing (browser/HTTP) user agent strings. The goal is to reliably detect whether:33 34* User agent is a mobile, tablet or PC based device35* User agent has touch capabilities (has touch screen)36 37`user_agents` relies on the excellent [ua-parser](https://github.com/ua-parser/uap-python) to do the actual parsing of the raw user agent string.38 39Installation40------------41 42![Build status](https://secure.travis-ci.org/selwin/python-user-agents.png)43 44`user-agents` is hosted on [PyPI](http://pypi.python.org/pypi/user-agents/) and can be installed as such:45 46    pip install pyyaml ua-parser user-agents47 48Alternatively, you can also get the latest source code from [Github](https://github.com/selwin/python-user-agents) and install it manually.49 50Usage51-----52 53Various basic information that can help you identify visitors can be accessed `browser`, `device` and `os` attributes. For example:54 55```python56from user_agents import parse57 58# iPhone's user agent string59ua_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'60user_agent = parse(ua_string)61 62# Accessing user agent's browser attributes63user_agent.browser  # returns Browser(family=u'Mobile Safari', version=(5, 1), version_string='5.1')64user_agent.browser.family  # returns 'Mobile Safari'65user_agent.browser.version  # returns (5, 1)66user_agent.browser.version_string   # returns '5.1'67 68# Accessing user agent's operating system properties69user_agent.os  # returns OperatingSystem(family=u'iOS', version=(5, 1), version_string='5.1')70user_agent.os.family  # returns 'iOS'71user_agent.os.version  # returns (5, 1)72user_agent.os.version_string  # returns '5.1'73 74# Accessing user agent's device properties75user_agent.device  # returns Device(family=u'iPhone', brand=u'Apple', model=u'iPhone')76user_agent.device.family  # returns 'iPhone'77user_agent.device.brand # returns 'Apple'78user_agent.device.model # returns 'iPhone'79 80# Viewing a pretty string version81str(user_agent) # returns "iPhone / iOS 5.1 / Mobile Safari 5.1"82```83 84`user_agents` also expose a few other more "sophisticated" attributes that are derived from one or more basic attributes defined above. As for now, these attributes should correctly identify popular platforms/devices, pull requests to support smaller ones are always welcome.85 86Currently these attributes are supported:87 88* `is_mobile`: whether user agent is identified as a mobile phone (iPhone, Android phones, Blackberry, Windows Phone devices etc)89* `is_tablet`: whether user agent is identified as a tablet device (iPad, Kindle Fire, Nexus 7 etc)90* `is_pc`: whether user agent is identified to be running a traditional "desktop" OS (Windows, OS X, Linux)91* `is_touch_capable`: whether user agent has touch capabilities92* `is_bot`: whether user agent is a search engine crawler/spider93 94For example:95 96```python97from user_agents import parse98 99# Let's start from an old, non touch Blackberry device100ua_string = 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/331 UNTRUSTED/1.0 3gpp-gba'101user_agent = parse(ua_string)102user_agent.is_mobile # returns True103user_agent.is_tablet # returns False104user_agent.is_touch_capable # returns False105user_agent.is_pc # returns False106user_agent.is_bot # returns False107str(user_agent) # returns "BlackBerry 9700 / BlackBerry OS 5 / BlackBerry 9700"108 109# Now a Samsung Galaxy S3110ua_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'111user_agent = parse(ua_string)112user_agent.is_mobile # returns True113user_agent.is_tablet # returns False114user_agent.is_touch_capable # returns True115user_agent.is_pc # returns False116user_agent.is_bot # returns False117str(user_agent) # returns "Samsung GT-I9300 / Android 4.0.4 / Android 4.0.4"118 119# iPad's user agent string120ua_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'121user_agent = parse(ua_string)122user_agent.is_mobile # returns False123user_agent.is_tablet # returns True124user_agent.is_touch_capable # returns True125user_agent.is_pc # returns False126user_agent.is_bot # returns False127str(user_agent) # returns "iPad / iOS 3.2 / Mobile Safari 4.0.4"128 129# Kindle Fire's user agent string130ua_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'131user_agent = parse(ua_string)132user_agent.is_mobile # returns False133user_agent.is_tablet # returns True134user_agent.is_touch_capable # returns True135user_agent.is_pc # returns False136user_agent.is_bot # returns False137str(user_agent) # returns "Kindle / Android / Amazon Silk 1.1.0-80"138 139# Touch capable Windows 8 device140ua_string = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)'141user_agent = parse(ua_string)142user_agent.is_mobile # returns False143user_agent.is_tablet # returns False144user_agent.is_touch_capable # returns True145user_agent.is_pc # returns True146user_agent.is_bot # returns False147str(user_agent) # returns "PC / Windows 8 / IE 10"148```149 150Running Tests151-------------152 153    python -m unittest discover154 155Changelog156---------157### Version 2.2.0 (2020-08-23)158* `ua-parser` >= 0.10.0 is required. Thanks @jnozsc!159* Added `get_device()`, `get_os()` and `get_browser()` instance methods160to `UserAgent`. Thanks @rodrigondec!161 162### Version 2.1 (2020-02-08)163 164* `python-user-agents` now require `ua-parser>=0.9.0`. Thanks @jnozsc!165* Properly detect Chrome Mobile browser families. Thanks @jnozsc!166 167### Version 2.0 (2019-04-07)168 169* `python-user-agents` now require `ua-parser>=0.8.0`. Thanks @IMDagger!170 171### Version 1.1172 173* Fixes packaging issue174 175### Version 1.0176 177* Adds compatibility with `ua-parser` 0.4.0178* Access to more device information in `user_agent.device.brand` and `user_agent.device.model`179 180### Version 0.3.2181 182* Better mobile detection183* Better PC detection184 185### Version 0.3.1186 187* user\_agent.is\_mobile returns True when mobile spider is detected188 189### Version 0.3.0190 191* Added **str**/**unicode** methods for convenience of pretty string192 193### Version 0.2.0194 195* Fixed errors when running against newer versions if ua-parser196* Support for Python 3197 198### Version 0.1.1199 200* Added `is_bot` property201* Symbian OS devices are now detected as a mobile device202 203### Version 0.1204 205* Initial release206 207Developed by the cool guys at [Stamps](http://stamps.co.id).208 209 210 
codekingpro/portable-devtools · Team Ai