Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 11eb03c

Browse filesBrowse files
committed
Fixed markdown in README.md
1 parent 5fce2a6 commit 11eb03c
Copy full SHA for 11eb03c

File tree

Expand file treeCollapse file tree

1 file changed

+103
-107
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+103
-107
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+103-107Lines changed: 103 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Python User Agents
2-
==================
1+
# Python User Agents
32

43
``user_agents`` is a Python library that provides an easy way to identify/detect devices like mobile
54
phones, tablets and their capabilities by parsing (browser/HTTP) user agent strings. The goal is to reliably detect whether:
@@ -11,10 +10,9 @@ phones, tablets and their capabilities by parsing (browser/HTTP) user agent stri
1110
actual parsing of the raw user agent string.
1211

1312

14-
Installation
15-
============
13+
## Installation
1614

17-
.. image:: https://secure.travis-ci.org/selwin/python-user-agents.png
15+
![Image](https://secure.travis-ci.org/selwin/python-user-agents.png)
1816

1917
``user-agents`` is hosted on `PyPI <http://pypi.python.org/pypi/user-agents/>`_ and can be installed as such::
2018

@@ -23,41 +21,40 @@ Installation
2321
Alternatively, you can also get the latest source code from
2422
`Github`_ and install it manually.
2523

26-
Usage
27-
=====
24+
## Usage
2825

2926
Various basic information that can help you identify visitors can be accessed `browser`, `device`
3027
and `os` attributes. For example:
3128

32-
.. code-block:: python
29+
```python
3330

34-
from user_agents import parse
31+
from user_agents import parse
3532

36-
# iPhone's user agent string
37-
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'
38-
user_agent = parse(ua_string)
33+
# iPhone's user agent string
34+
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'
35+
user_agent = parse(ua_string)
3936

40-
# Accessing user agent's browser attributes
41-
user_agent.browser # returns Browser(family=u'Mobile Safari', version=(5, 1), version_string='5.1')
42-
user_agent.browser.family # returns 'Mobile Safari'
43-
user_agent.browser.version # returns (5, 1)
44-
user_agent.browser.version_string # returns '5.1'
45-
46-
# Accessing user agent's operating system properties
47-
user_agent.os # returns OperatingSystem(family=u'iOS', version=(5, 1), version_string='5.1')
48-
user_agent.os.family # returns 'iOS'
49-
user_agent.os.version # returns (5, 1)
50-
user_agent.os.version_string # returns '5.1'
51-
52-
# Accessing user agent's device properties
53-
user_agent.device # returns Device(family=u'iPhone', brand=u'Apple', model=u'iPhone')
54-
user_agent.device.family # returns 'iPhone'
55-
user_agent.device.brand # returns 'Apple'
56-
user_agent.device.model # returns 'iPhone'
37+
# Accessing user agent's browser attributes
38+
user_agent.browser # returns Browser(family=u'Mobile Safari', version=(5, 1), version_string='5.1')
39+
user_agent.browser.family # returns 'Mobile Safari'
40+
user_agent.browser.version # returns (5, 1)
41+
user_agent.browser.version_string # returns '5.1'
5742

58-
# Viewing a pretty string version
59-
str(user_agent) # returns "iPhone / iOS 5.1 / Mobile Safari 5.1"
43+
# Accessing user agent's operating system properties
44+
user_agent.os # returns OperatingSystem(family=u'iOS', version=(5, 1), version_string='5.1')
45+
user_agent.os.family # returns 'iOS'
46+
user_agent.os.version # returns (5, 1)
47+
user_agent.os.version_string # returns '5.1'
6048

49+
# Accessing user agent's device properties
50+
user_agent.device # returns Device(family=u'iPhone', brand=u'Apple', model=u'iPhone')
51+
user_agent.device.family # returns 'iPhone'
52+
user_agent.device.brand # returns 'Apple'
53+
user_agent.device.model # returns 'iPhone'
54+
55+
# Viewing a pretty string version
56+
str(user_agent) # returns "iPhone / iOS 5.1 / Mobile Safari 5.1"
57+
```
6158

6259
``user_agents`` also expose a few other more "sophisticated" attributes that are derived from one or
6360
more basic attributes defined above. As for now, these attributes should correctly identify
@@ -74,105 +71,104 @@ Currently these attributes are supported:
7471

7572
For example:
7673

77-
.. code-block:: python
78-
79-
from user_agents import parse
80-
81-
# Let's start from an old, non touch Blackberry device
82-
ua_string = 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/331 UNTRUSTED/1.0 3gpp-gba'
83-
user_agent = parse(ua_string)
84-
user_agent.is_mobile # returns True
85-
user_agent.is_tablet # returns False
86-
user_agent.is_touch_capable # returns False
87-
user_agent.is_pc # returns False
88-
user_agent.is_bot # returns False
89-
str(user_agent) # returns "BlackBerry 9700 / BlackBerry OS 5 / BlackBerry 9700"
90-
91-
# Now a Samsung Galaxy S3
92-
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'
93-
user_agent = parse(ua_string)
94-
user_agent.is_mobile # returns True
95-
user_agent.is_tablet # returns False
96-
user_agent.is_touch_capable # returns True
97-
user_agent.is_pc # returns False
98-
user_agent.is_bot # returns False
99-
str(user_agent) # returns "Samsung GT-I9300 / Android 4.0.4 / Android 4.0.4"
100-
101-
# iPad's user agent string
102-
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'
103-
user_agent = parse(ua_string)
104-
user_agent.is_mobile # returns False
105-
user_agent.is_tablet # returns True
106-
user_agent.is_touch_capable # returns True
107-
user_agent.is_pc # returns False
108-
user_agent.is_bot # returns False
109-
str(user_agent) # returns "iPad / iOS 3.2 / Mobile Safari 4.0.4"
110-
111-
# Kindle Fire's user agent string
112-
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'
113-
user_agent = parse(ua_string)
114-
user_agent.is_mobile # returns False
115-
user_agent.is_tablet # returns True
116-
user_agent.is_touch_capable # returns True
117-
user_agent.is_pc # returns False
118-
user_agent.is_bot # returns False
119-
str(user_agent) # returns "Kindle / Android / Amazon Silk 1.1.0-80"
120-
121-
# Touch capable Windows 8 device
122-
ua_string = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)'
123-
user_agent = parse(ua_string)
124-
user_agent.is_mobile # returns False
125-
user_agent.is_tablet # returns False
126-
user_agent.is_touch_capable # returns True
127-
user_agent.is_pc # returns True
128-
user_agent.is_bot # returns False
129-
str(user_agent) # returns "PC / Windows 8 / IE 10"
130-
131-
132-
Running Tests
133-
=============
74+
``` python
75+
76+
from user_agents import parse
77+
78+
# Let's start from an old, non touch Blackberry device
79+
ua_string = 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/331 UNTRUSTED/1.0 3gpp-gba'
80+
user_agent = parse(ua_string)
81+
user_agent.is_mobile # returns True
82+
user_agent.is_tablet # returns False
83+
user_agent.is_touch_capable # returns False
84+
user_agent.is_pc # returns False
85+
user_agent.is_bot # returns False
86+
str(user_agent) # returns "BlackBerry 9700 / BlackBerry OS 5 / BlackBerry 9700"
87+
88+
# Now a Samsung Galaxy S3
89+
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'
90+
user_agent = parse(ua_string)
91+
user_agent.is_mobile # returns True
92+
user_agent.is_tablet # returns False
93+
user_agent.is_touch_capable # returns True
94+
user_agent.is_pc # returns False
95+
user_agent.is_bot # returns False
96+
str(user_agent) # returns "Samsung GT-I9300 / Android 4.0.4 / Android 4.0.4"
97+
98+
# iPad's user agent string
99+
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'
100+
user_agent = parse(ua_string)
101+
user_agent.is_mobile # returns False
102+
user_agent.is_tablet # returns True
103+
user_agent.is_touch_capable # returns True
104+
user_agent.is_pc # returns False
105+
user_agent.is_bot # returns False
106+
str(user_agent) # returns "iPad / iOS 3.2 / Mobile Safari 4.0.4"
107+
108+
# Kindle Fire's user agent string
109+
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'
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 "Kindle / Android / Amazon Silk 1.1.0-80"
117+
118+
# Touch capable Windows 8 device
119+
ua_string = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)'
120+
user_agent = parse(ua_string)
121+
user_agent.is_mobile # returns False
122+
user_agent.is_tablet # returns False
123+
user_agent.is_touch_capable # returns True
124+
user_agent.is_pc # returns True
125+
user_agent.is_bot # returns False
126+
str(user_agent) # returns "PC / Windows 8 / IE 10"
127+
```
128+
129+
## Running Tests
134130

135131
python -m unittest discover
136132

137133

138-
Changelog
139-
=========
134+
## Changelog
135+
136+
### Version 1.0.0
140137

141-
Version 1.0.0
142-
-------------
143138
* Fixes packaging issue
144139

145-
Version 1.0
146-
-----------
140+
### Version 1.0
141+
147142
* Adds compatibility with ``ua-parser`` 0.4.0
148143
* Access to more device information in ``user_agent.device.brand`` and ``user_agent.device.model``
149144

150-
=======
151-
Version 0.3.2
152-
-------------
145+
===
146+
147+
### Version 0.3.2
148+
153149
* Better mobile detection
154150
* Better PC detection
155151

156-
Version 0.3.1
157-
-------------
152+
### Version 0.3.1
153+
158154
* user_agent.is_mobile returns True when mobile spider is detected
159155

160-
Version 0.3.0
161-
-------------
156+
### Version 0.3.0
157+
162158
* Added __str__/__unicode__ methods for convenience of pretty string
163159

164-
Version 0.2.0
165-
-------------
160+
### Version 0.2.0
161+
166162
* Fixed errors when running against newer versions if ua-parser
167163
* Support for Python 3
168164

169-
Version 0.1.1
170-
-------------
165+
### Version 0.1.1
166+
171167
* Added ``is_bot`` property
172168
* Symbian OS devices are now detected as a mobile device
173169

174-
Version 0.1
175-
-----------
170+
### Version 0.1
171+
176172
* Initial release
177173

178174

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.