### Install Python User Agents Library Source: https://github.com/selwin/python-user-agents/blob/master/README.md Instructions for installing the `user-agents` library using pip, including its dependencies `pyyaml` and `ua-parser`. ```Shell pip install pyyaml ua-parser user-agents ``` -------------------------------- ### Identify Device Type and Capabilities with Python User Agents Source: https://github.com/selwin/python-user-agents/blob/master/README.md Illustrates how to use `user_agents` to determine specific device characteristics such as `is_mobile`, `is_tablet`, `is_pc`, `is_touch_capable`, and `is_bot`. Examples include various user agent strings for Blackberry, Samsung Galaxy S3, iPad, and Kindle Fire. ```Python from user_agents import parse # Let's start from an old, non touch Blackberry device ua_string = 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/331 UNTRUSTED/1.0 3gpp-gba' user_agent = parse(ua_string) user_agent.is_mobile # returns True user_agent.is_tablet # returns False user_agent.is_touch_capable # returns False user_agent.is_pc # returns False user_agent.is_bot # returns False str(user_agent) # returns "BlackBerry 9700 / BlackBerry OS 5 / BlackBerry 9700" # Now a Samsung Galaxy S3 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' user_agent = parse(ua_string) user_agent.is_mobile # returns True user_agent.is_tablet # returns False user_agent.is_touch_capable # returns True user_agent.is_pc # returns False user_agent.is_bot # returns False str(user_agent) # returns "Samsung GT-I9300 / Android 4.0.4 / Android 4.0.4" # iPad's user agent string 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' user_agent = parse(ua_string) user_agent.is_mobile # returns False user_agent.is_tablet # returns True user_agent.is_touch_capable # returns True user_agent.is_pc # returns False user_agent.is_bot # returns False str(user_agent) # returns "iPad / iOS 3.2 / Mobile Safari 4.0.4" # Kindle Fire's user agent string 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' user_agent = parse(ua_string) user_agent.is_mobile # returns False user_agent.is_tablet # returns True user_agent.is_touch_capable # returns True user_agent.is_pc # returns False user_agent.is_bot # returns False str(user_agent) # returns "Kindle / Android / Amazon Silk 1.1.0-80" ``` -------------------------------- ### Parse User Agent String and Access Basic Device Attributes in Python Source: https://github.com/selwin/python-user-agents/blob/master/README.md Demonstrates how to parse a user agent string using `user_agents.parse` and access its `browser`, `os`, and `device` attributes to retrieve family, version, brand, and model information. Also shows how to get a pretty string representation of the parsed user agent. ```Python from user_agents import parse # iPhone's user agent string 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' user_agent = parse(ua_string) # Accessing user agent's browser attributes user_agent.browser # returns Browser(family=u'Mobile Safari', version=(5, 1), version_string='5.1') user_agent.browser.family # returns 'Mobile Safari' user_agent.browser.version # returns (5, 1) user_agent.browser.version_string # returns '5.1' # Accessing user agent's operating system properties user_agent.os # returns OperatingSystem(family=u'iOS', version=(5, 1), version_string='5.1') user_agent.os.family # returns 'iOS' user_agent.os.version # returns (5, 1) user_agent.os.version_string # returns '5.1' # Accessing user agent's device properties user_agent.device # returns Device(family=u'iPhone', brand=u'Apple', model=u'iPhone') user_agent.device.family # returns 'iPhone' user_agent.device.brand # returns 'Apple' user_agent.device.model # returns 'iPhone' # Viewing a pretty string version str(user_agent) # returns "iPhone / iOS 5.1 / Mobile Safari 5.1" ``` -------------------------------- ### Parse User Agent String and Check Device Properties (Python) Source: https://github.com/selwin/python-user-agents/blob/master/README.md This Python snippet demonstrates how to parse a user agent string using the `python-user-agents` library. It shows how to access various boolean properties like `is_mobile`, `is_tablet`, `is_touch_capable`, `is_pc`, and `is_bot` to identify device characteristics. It also illustrates how to get a human-readable string representation of the parsed user agent. ```Python ua_string = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)' user_agent = parse(ua_string) user_agent.is_mobile # returns False user_agent.is_tablet # returns False user_agent.is_touch_capable # returns True user_agent.is_pc # returns True user_agent.is_bot # returns False str(user_agent) # returns "PC / Windows 8 / IE 10" ``` -------------------------------- ### UserAgent Class Instance Methods (APIDOC) Source: https://github.com/selwin/python-user-agents/blob/master/README.md This API documentation outlines instance methods available on the `UserAgent` class, providing structured access to device, operating system, and browser details extracted from a parsed user agent string. ```APIDOC UserAgent Class Methods: get_device(): Returns an object containing device information (e.g., brand, model). get_os(): Returns an object containing operating system information (e.g., family, version). get_browser(): Returns an object containing browser information (e.g., family, version). UserAgent Class Properties (example): user_agent.device.brand: Accesses the device brand. user_agent.device.model: Accesses the device model. ``` -------------------------------- ### Run Unit Tests for python-user-agents (Shell) Source: https://github.com/selwin/python-user-agents/blob/master/README.md This command line snippet shows how to execute the unit tests for the `python-user-agents` library. It uses Python's built-in `unittest` module to discover and run tests within the project directory. ```Shell python -m unittest discover ``` -------------------------------- ### Python Project Requirements File Source: https://github.com/selwin/python-user-agents/blob/master/requirements.txt This snippet defines the essential Python packages and their precise versions required for the `python-user-agents` project. It includes specific version constraints for `PyYAML` to ensure compatibility across different Python 3 versions, notably Python 3.4. ```Python ua-parser==0.10.0 PyYAML==5.4; python_version != '3.4' PyYAML==5.4; python_version == '3.4' # the last version support py34 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.