You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8e43097
Browse filesBrowse the repository at this point in the historyBrowse files
- Add is_tv for smart TVs and streaming devices, which were reported
as touch capable tablets, phones or PCs
- Catch bots ua-parser misses, using product tokens, contact URLs,
contact emails and headless browsers
- Treat Generic Tablet as a tablet and Dalvik clients as phones, and
add KaiOS to the mobile OS families
- Accept None and bytes in parse() instead of raising TypeError
- Move to the current ua-parser API, requiring ua-parser>=1.0.0, and
add a fast extra for the Rust-backed parser
- Run CI against both parsers and update the publish workflow actions
Copy file name to clipboardExpand all lines: README.md
+22-3Lines changed: 22 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,11 @@ to do the actual parsing of the raw user agent string.
25
25
26
26
pip install user-agents-ng
27
27
28
+
For a roughly 20x parsing speedup on uncached user agents, install the optional
29
+
Rust-backed parser too. It's a drop-in change, no code needs updating:
30
+
31
+
pip install "user-agents-ng[fast]"
32
+
28
33
### Migrating from `user-agents`
29
34
30
35
`user-agents-ng` is a drop-in replacement. Swap the dependency and your code
@@ -81,8 +86,13 @@ Currently these attributes are supported:
81
86
*`is_mobile`: whether user agent is identified as a mobile phone (iPhone, Android phones, Blackberry, Windows Phone devices etc)
82
87
*`is_tablet`: whether user agent is identified as a tablet device (iPad, Kindle Fire, Nexus 7 etc)
83
88
*`is_pc`: whether user agent is identified to be running a traditional "desktop" OS (Windows, OS X, Linux)
89
+
*`is_tv`: whether user agent is identified as a smart TV or streaming device (Samsung Tizen, LG webOS, Android TV, Fire TV, Roku, Chromecast etc)
84
90
*`is_touch_capable`: whether user agent has touch capabilities
85
-
*`is_bot`: whether user agent is a search engine crawler/spider
91
+
*`is_bot`: whether user agent is a crawler, spider or headless browser. Besides the bots ua-parser knows about, this catches any user agent with a bot-style product token (`Applebot/0.1`), a contact URL (`+http://example.com/bot`) or a contact email address
92
+
*`is_email_client`: whether user agent is an email client (Outlook, Thunderbird, Apple Mail etc)
93
+
94
+
`parse()` also accepts `bytes` and `None`, so a raw header or a request with no
95
+
`User-Agent` header at all won't raise an exception.
description = "A maintained successor to user-agents: identify devices (phones, tablets) and their capabilities by parsing browser user agent strings."
self.assertEqual(ua_str, "iPhone / iOS 5.1 / Mobile Safari 5.1")
246
246
self.assertIsInstance(ua_str, str)
247
247
248
+
deftest_missing_user_agent(self):
249
+
forua_stringin (None, '', b''):
250
+
ua=parse(ua_string)
251
+
self.assertEqual(ua.ua_string, '')
252
+
self.assertEqual(str(ua), 'Other / Other / Other')
253
+
self.assertFalse(ua.is_bot)
254
+
255
+
deftest_bytes_user_agent(self):
256
+
ua=parse(iphone_ua_string.encode('latin-1'))
257
+
self.assertEqual(ua.ua_string, iphone_ua_string)
258
+
self.assertTrue(ua.is_mobile)
259
+
260
+
deftest_is_bot_undetected_by_ua_parser(self):
261
+
forua_stringin (
262
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15 (Applebot/0.1; +http://www.apple.com/go/applebot)',
263
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15 (Amazonbot/0.1; +https://developer.amazon.com/support/amazonbot)',
264
+
'Mozilla/5.0 (Linux; Android 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Mobile Safari/537.36 (compatible; Bytespider; spider-feedback@bytedance.com)',
265
+
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/140.0.0.0 Safari/537.36',
0 commit comments