{"id":13540179,"url":"https://github.com/selwin/python-user-agents","last_synced_at":"2025-05-14T00:05:29.032Z","repository":{"id":6218388,"uuid":"7449695","full_name":"selwin/python-user-agents","owner":"selwin","description":"A Python library that provides an easy way to identify devices like mobile phones, tablets and their capabilities by parsing (browser) user agent strings.","archived":false,"fork":false,"pushed_at":"2023-02-16T01:51:50.000Z","size":116,"stargazers_count":1469,"open_issues_count":46,"forks_count":197,"subscribers_count":39,"default_branch":"master","last_synced_at":"2025-04-10T02:15:50.504Z","etag":null,"topics":["browser-detection","python","user-agent-detection"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/selwin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null}},"created_at":"2013-01-05T00:44:11.000Z","updated_at":"2025-04-01T12:48:46.000Z","dependencies_parsed_at":"2024-01-29T18:51:49.579Z","dependency_job_id":null,"html_url":"https://github.com/selwin/python-user-agents","commit_stats":{"total_commits":123,"total_committers":33,"mean_commits":3.727272727272727,"dds":0.5447154471544715,"last_synced_commit":"5f2d80ab7f9833481089813f48241098679f5f05"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selwin%2Fpython-user-agents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selwin%2Fpython-user-agents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selwin%2Fpython-user-agents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selwin%2Fpython-user-agents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/selwin","download_url":"https://codeload.github.com/selwin/python-user-agents/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142906,"owners_count":21054671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser-detection","python","user-agent-detection"],"created_at":"2024-08-01T09:01:42.250Z","updated_at":"2025-04-10T02:15:55.533Z","avatar_url":"https://github.com/selwin.png","language":"Python","readme":"Python User Agents\n==================\n\n`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:\n\n* User agent is a mobile, tablet or PC based device\n* User agent has touch capabilities (has touch screen)\n\n`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.\n\nInstallation\n------------\n\n![Build status](https://secure.travis-ci.org/selwin/python-user-agents.png)\n\n`user-agents` is hosted on [PyPI](http://pypi.python.org/pypi/user-agents/) and can be installed as such:\n\n    pip install pyyaml ua-parser user-agents\n\nAlternatively, you can also get the latest source code from [Github](https://github.com/selwin/python-user-agents) and install it manually.\n\nUsage\n-----\n\nVarious basic information that can help you identify visitors can be accessed `browser`, `device` and `os` attributes. For example:\n\n```python\nfrom user_agents import parse\n\n# iPhone's user agent string\nua_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'\nuser_agent = parse(ua_string)\n\n# Accessing user agent's browser attributes\nuser_agent.browser  # returns Browser(family=u'Mobile Safari', version=(5, 1), version_string='5.1')\nuser_agent.browser.family  # returns 'Mobile Safari'\nuser_agent.browser.version  # returns (5, 1)\nuser_agent.browser.version_string   # returns '5.1'\n\n# Accessing user agent's operating system properties\nuser_agent.os  # returns OperatingSystem(family=u'iOS', version=(5, 1), version_string='5.1')\nuser_agent.os.family  # returns 'iOS'\nuser_agent.os.version  # returns (5, 1)\nuser_agent.os.version_string  # returns '5.1'\n\n# Accessing user agent's device properties\nuser_agent.device  # returns Device(family=u'iPhone', brand=u'Apple', model=u'iPhone')\nuser_agent.device.family  # returns 'iPhone'\nuser_agent.device.brand # returns 'Apple'\nuser_agent.device.model # returns 'iPhone'\n\n# Viewing a pretty string version\nstr(user_agent) # returns \"iPhone / iOS 5.1 / Mobile Safari 5.1\"\n```\n\n`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.\n\nCurrently these attributes are supported:\n\n* `is_mobile`: whether user agent is identified as a mobile phone (iPhone, Android phones, Blackberry, Windows Phone devices etc)\n* `is_tablet`: whether user agent is identified as a tablet device (iPad, Kindle Fire, Nexus 7 etc)\n* `is_pc`: whether user agent is identified to be running a traditional \"desktop\" OS (Windows, OS X, Linux)\n* `is_touch_capable`: whether user agent has touch capabilities\n* `is_bot`: whether user agent is a search engine crawler/spider\n\nFor example:\n\n```python\nfrom user_agents import parse\n\n# Let's start from an old, non touch Blackberry device\nua_string = 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/331 UNTRUSTED/1.0 3gpp-gba'\nuser_agent = parse(ua_string)\nuser_agent.is_mobile # returns True\nuser_agent.is_tablet # returns False\nuser_agent.is_touch_capable # returns False\nuser_agent.is_pc # returns False\nuser_agent.is_bot # returns False\nstr(user_agent) # returns \"BlackBerry 9700 / BlackBerry OS 5 / BlackBerry 9700\"\n\n# Now a Samsung Galaxy S3\nua_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'\nuser_agent = parse(ua_string)\nuser_agent.is_mobile # returns True\nuser_agent.is_tablet # returns False\nuser_agent.is_touch_capable # returns True\nuser_agent.is_pc # returns False\nuser_agent.is_bot # returns False\nstr(user_agent) # returns \"Samsung GT-I9300 / Android 4.0.4 / Android 4.0.4\"\n\n# iPad's user agent string\nua_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'\nuser_agent = parse(ua_string)\nuser_agent.is_mobile # returns False\nuser_agent.is_tablet # returns True\nuser_agent.is_touch_capable # returns True\nuser_agent.is_pc # returns False\nuser_agent.is_bot # returns False\nstr(user_agent) # returns \"iPad / iOS 3.2 / Mobile Safari 4.0.4\"\n\n# Kindle Fire's user agent string\nua_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'\nuser_agent = parse(ua_string)\nuser_agent.is_mobile # returns False\nuser_agent.is_tablet # returns True\nuser_agent.is_touch_capable # returns True\nuser_agent.is_pc # returns False\nuser_agent.is_bot # returns False\nstr(user_agent) # returns \"Kindle / Android / Amazon Silk 1.1.0-80\"\n\n# Touch capable Windows 8 device\nua_string = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)'\nuser_agent = parse(ua_string)\nuser_agent.is_mobile # returns False\nuser_agent.is_tablet # returns False\nuser_agent.is_touch_capable # returns True\nuser_agent.is_pc # returns True\nuser_agent.is_bot # returns False\nstr(user_agent) # returns \"PC / Windows 8 / IE 10\"\n```\n\nRunning Tests\n-------------\n\n    python -m unittest discover\n\nChangelog\n---------\n### Version 2.2.0 (2020-08-23)\n* `ua-parser` \u003e= 0.10.0 is required. Thanks @jnozsc!\n* Added `get_device()`, `get_os()` and `get_browser()` instance methods\nto `UserAgent`. Thanks @rodrigondec!\n\n### Version 2.1 (2020-02-08)\n\n* `python-user-agents` now require `ua-parser\u003e=0.9.0`. Thanks @jnozsc!\n* Properly detect Chrome Mobile browser families. Thanks @jnozsc!\n\n### Version 2.0 (2019-04-07)\n\n* `python-user-agents` now require `ua-parser\u003e=0.8.0`. Thanks @IMDagger!\n\n### Version 1.1\n\n* Fixes packaging issue\n\n### Version 1.0\n\n* Adds compatibility with `ua-parser` 0.4.0\n* Access to more device information in `user_agent.device.brand` and `user_agent.device.model`\n\n### Version 0.3.2\n\n* Better mobile detection\n* Better PC detection\n\n### Version 0.3.1\n\n* user\\_agent.is\\_mobile returns True when mobile spider is detected\n\n### Version 0.3.0\n\n* Added **str**/**unicode** methods for convenience of pretty string\n\n### Version 0.2.0\n\n* Fixed errors when running against newer versions if ua-parser\n* Support for Python 3\n\n### Version 0.1.1\n\n* Added `is_bot` property\n* Symbian OS devices are now detected as a mobile device\n\n### Version 0.1\n\n* Initial release\n\nDeveloped by the cool guys at [Stamps](http://stamps.co.id).\n","funding_links":[],"categories":["Text Processing","资源列表","\u003ca id=\"76df273beb09f6732b37a6420649179c\"\u003e\u003c/a\u003e浏览器\u0026\u0026browser","文本处理","Python","\u003ca id=\"47a03071becd6df66b469df7c2c6f9b5\"\u003e\u003c/a\u003e工具","Text Processing [🔝](#readme)","Awesome Python"],"sub_categories":["文本处理","\u003ca id=\"f2c76d99a0b1fda124d210bd1bbc8f3f\"\u003e\u003c/a\u003eWordlist生成","\u003ca id=\"3828e67170e5db714c9c16f663b42a5e\"\u003e\u003c/a\u003e新添加的","Text Processing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselwin%2Fpython-user-agents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fselwin%2Fpython-user-agents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselwin%2Fpython-user-agents/lists"}