METADATA 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. Metadata-Version: 2.4
  2. Name: fake-useragent
  3. Version: 2.2.0
  4. Summary: Up-to-date simple useragent faker with real world database
  5. Author-email: Melroy van den Berg <melroy@melroy.org>, Victor Kovtun <hellysmile@gmail.com>
  6. License-Expression: Apache-2.0
  7. Project-URL: Homepage, https://github.com/fake-useragent/fake-useragent
  8. Keywords: agent,fake,fake user agent,fake useragent,user,user agent,useragent
  9. Classifier: Development Status :: 5 - Production/Stable
  10. Classifier: Intended Audience :: Developers
  11. Classifier: Operating System :: MacOS :: MacOS X
  12. Classifier: Operating System :: Microsoft :: Windows
  13. Classifier: Operating System :: OS Independent
  14. Classifier: Operating System :: POSIX
  15. Classifier: Programming Language :: Python
  16. Classifier: Programming Language :: Python :: 3 :: Only
  17. Classifier: Programming Language :: Python :: 3.9
  18. Classifier: Programming Language :: Python :: 3.10
  19. Classifier: Programming Language :: Python :: 3.11
  20. Classifier: Programming Language :: Python :: 3.12
  21. Classifier: Programming Language :: Python :: 3.13
  22. Classifier: Topic :: Internet :: WWW/HTTP
  23. Classifier: Topic :: Software Development
  24. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  25. Classifier: Topic :: Utilities
  26. Requires-Python: >=3.9
  27. Description-Content-Type: text/markdown
  28. License-File: LICENSE
  29. License-File: AUTHORS
  30. Requires-Dist: importlib-resources>=6; python_version < "3.10"
  31. Dynamic: license-file
  32. [![Test & Deploy fake-useragent](https://github.com/fake-useragent/fake-useragent/actions/workflows/action.yml/badge.svg?branch=main)](https://github.com/fake-useragent/fake-useragent/actions/workflows/action.yml?query=branch%3Amain)
  33. [![Ruff linter](https://github.com/fake-useragent/fake-useragent/actions/workflows/ruff.yml/badge.svg?branch=main)](https://github.com/fake-useragent/fake-useragent/actions/workflows/ruff.yml?query=branch%3Amain)
  34. [![CodeQL](https://github.com/fake-useragent/fake-useragent/actions/workflows/codeql.yml/badge.svg?branch=main)](https://github.com/fake-useragent/fake-useragent/actions/workflows/codeql.yml?query=branch%3Amain)
  35. # fake-useragent
  36. Up-to-date simple useragent faker with real world database.
  37. ## Features
  38. - Data is pre-downloaded & post-processed from [Intoli LLC](https://github.com/intoli/user-agents/tree/main/src) and the data is part of the package itself
  39. - The data consists of a wide range of browser agents and various browsers
  40. - Retrieves user-agent strings (both of type: `desktop`, `tablet` and/or `mobile` UAs)
  41. - Retrieve user-agent Python dictionary (aka object), with fields like `useragent`, `percent`, `type`, `device_brand`, `browser`, `browser_version`, `os`, `os_version` and `platform`
  42. - Supports Python 3.x
  43. ### Installation
  44. ```sh
  45. pip install fake-useragent
  46. ```
  47. Or if you have multiple Python / pip versions installed, use `pip3`:
  48. ```sh
  49. pip3 install fake-useragent
  50. ```
  51. ### Usage
  52. Simple usage examples below, see also next chapters in this readme for more advanced usages:
  53. ```py
  54. from fake_useragent import UserAgent
  55. ua = UserAgent()
  56. # Get a random browser user-agent string
  57. print(ua.random)
  58. # Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0
  59. # Or get user-agent string from a specific browser
  60. print(ua.chrome)
  61. # Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
  62. print(ua.google)
  63. # Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/343.0.695551749 Mobile/15E148 Safari/604.1
  64. print(ua['Chrome'])
  65. # Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
  66. print(ua.firefox)
  67. # Mozilla/5.0 (Android 14; Mobile; rv:133.0) Gecko/133.0 Firefox/133.0
  68. print(ua.ff)
  69. # Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0
  70. print(ua.safari)
  71. # Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Mobile/15E148 Safari/604.1 Ddg/17.6
  72. print(ua.opera)
  73. # Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 OPR/114.0.0.0
  74. print(ua.edge)
  75. # Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0
  76. ```
  77. #### Additional usage
  78. Additional features that fake-useragent now offers since v1.2.0.
  79. If you want to specify your own browser list, you can do that via the `browsers` argument (default is: `["Google", "Chrome", "Firefox", "Edge", "Opera", "Safari", "Android", "Yandex Browser", "Samsung Internet", "Opera Mobile", "Mobile Safari", "Firefox Mobile", "Firefox iOS", "Chrome Mobile", "Chrome Mobile iOS", "Mobile Safari UI/WKWebView", "Edge Mobile", "DuckDuckGo Mobile", "MiuiBrowser", "Whale", "Twitter", "Facebook", "Amazon Silk"]`).
  80. This example will only return random user-agents from Edge and Chrome:
  81. ```py
  82. from fake_useragent import UserAgent
  83. ua = UserAgent(browsers=['Edge', 'Chrome'])
  84. ua.random
  85. ```
  86. _Note:_ Fakeuser-agent knowns about browsers: Chrome, Edge, Firefox, Safari, Opera, Android, Opera Mobile, Mobile Safari, Firefox Mobile, Firefox iOS, Chrome Mobile, Chrome Mobile iOS and more (see again full list above).
  87. _Note #2:_ Since fakeuser-agent v2.0.0 the browser names are case-sensitive!
  88. ---
  89. If you want to specify your own operating systems, you can do that via the `os` argument (default is: `["Windows", "Linux", "Ubuntu", "Chrome OS", "Mac OS X", "Android", "iOS"]`).
  90. In this example you will only get Linux user-agents back:
  91. ```py
  92. from fake_useragent import UserAgent
  93. ua = UserAgent(os='Linux')
  94. ua.random
  95. ```
  96. _Note:_ Since fakeuser-agent v2.0.0 the OS names are case-sensitive!
  97. ---
  98. You can also specify the type of platforms you want to use, you can do that via the `platforms` argument (default is `["desktop", "mobile", "tablet"]`).
  99. This example will only return random user-agents from a mobile device:
  100. ```py
  101. from fake_useragent import UserAgent
  102. ua = UserAgent(platforms='mobile')
  103. ua.random
  104. ```
  105. And a random user-agent from a desktop device:
  106. ```py
  107. from fake_useragent import UserAgent
  108. ua = UserAgent(platforms='desktop')
  109. ua.random
  110. ```
  111. ---
  112. If you want to return more recent user-agent strings, you can play with the `min_version` argument (default is: `0.0`, meaning all user agents will match).
  113. In this example you get only user agents that have a minimum version of 120.0:
  114. ```py
  115. from fake_useragent import UserAgent
  116. ua = UserAgent(min_version=120.0)
  117. ua.random
  118. ```
  119. ---
  120. For backwards compatibility, a minimum usage percentage can still be specified with the `min_percentage` argument. However, the current list of user agents does
  121. not contain this statistic. Therefore all of the user-agents will match.
  122. ---
  123. _Hint:_ Of-course you can **combine all those arguments** to you liking!
  124. #### User-agent Python Dictionary
  125. Since version 1.3.0 we now also offer you the following "get" properties which return the whole Python dictionary of the UA, instead of only the user-agent string:
  126. > **Warning**
  127. > Raw JSON objects (in a Python dictionaries) are returned "as is".
  128. > Meaning, this data structure could change in the future!
  129. >
  130. > Be aware that these "get" properties below might not return the same key/value pairs in the future.
  131. > Use `ua.random` or alike as mentioned above, if you want to use a stable interface.
  132. ```py
  133. from fake_useragent import UserAgent
  134. ua = UserAgent()
  135. # Random user-agent dictionary (object)
  136. ua.getRandom
  137. # {'percent': 0.8, 'useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.76', 'system': 'Edge 116.0 Win10', 'browser': 'edge', 'version': 116.0, 'os': 'win10'}
  138. # More get properties:
  139. ua.getFirefox
  140. # {'percent': 0.3, 'useragent': 'Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/118.0', 'system': 'Firefox 118.0 Win10', 'browser': 'firefox', 'version': 118.0, 'os': 'win10'}
  141. ua.getChrome
  142. ua.getSafari
  143. ua.getEdge
  144. # And a method with an argument.
  145. # This is exactly the same as using: ua.getFirefox
  146. ua.getBrowser('firefox')
  147. ```
  148. ### Notes
  149. You can override the fallback string using the `fallback` parameter, in very rare cases something failed:
  150. ```py
  151. from fake_useragent import UserAgent
  152. ua = UserAgent(fallback='your favorite Browser')
  153. # in case if something went wrong, one more time it is REALLY!!! rare case
  154. ua.random == 'your favorite Browser'
  155. ```
  156. If you will try to get unknown browser:
  157. ```py
  158. from fake_useragent import UserAgent
  159. ua = UserAgent()
  160. print(ua.unknown)
  161. #Error occurred during getting browser: randm, but was suppressed with fallback.
  162. #Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0
  163. ```
  164. If you need to safe some attributes from overriding them in UserAgent by `__getattr__` method
  165. use `safe_attrs` you can pass there attributes names.
  166. At least this will prevent you from raising FakeUserAgentError when attribute not found.
  167. For example, when using fake*useragent with `injections <https://github.com/tailhook/injections>`* you need to:
  168. ```py
  169. from fake_useragent import UserAgent
  170. ua = UserAgent(safe_attrs=('__injections__',))
  171. ```
  172. Please, do not use if you don't understand why you need this.
  173. This is magic for rarely extreme case.
  174. ### Experiencing issues?
  175. Make sure that you using latest version!
  176. ```sh
  177. pip install --upgrade fake-useragent
  178. ```
  179. Or if that isn't working, try to install the latest package version like this (`2.0.3` is an example, check what the [latest version is on PyPi](https://pypi.org/project/fake-useragent/#history)):
  180. ```sh
  181. pip install fake-useragent==2.0.3
  182. ```
  183. Check version via the Python console:
  184. ```py
  185. import fake_useragent
  186. print(fake_useragent.__version__)
  187. ```
  188. And you are always welcome to post [issues](https://github.com/fake-useragent/fake-useragent/issues).
  189. Please do not forget to mention the version that you are using.
  190. ### For Developers
  191. #### User-agent Data
  192. The user-agent data we retrieve from [user-agents.net](https://user-agents.net). Data is stored in [JSONlines](https://jsonlines.org/) format. File is located in the: `src/fake_useragent/data` directory.
  193. The data JSON file is part of the Python package, see [pyproject.toml](pyproject.toml). Read more about [Data files support](https://setuptools.pypa.io/en/latest/userguide/datafiles.html).
  194. #### Python Virtual Environment
  195. We encourage to use Python virtual environment before installing Pip packages, like so:
  196. ```sh
  197. python -m virtualenv env
  198. source env/bin/activate
  199. ```
  200. #### Local Install
  201. ```sh
  202. pip install -e .
  203. ```
  204. #### Tests
  205. ```sh
  206. pip install -r requirements.txt
  207. tox
  208. ```
  209. #### Linting
  210. To fix imports using ruff:
  211. ```sh
  212. pip install -r requirements.txt
  213. ruff check --select="I" --fix .
  214. ```
  215. Fix black code formatting errors:
  216. ```sh
  217. pip install -r requirements.txt
  218. black .
  219. ```
  220. _Note:_ When ruff v1.0 releases, we most likely move fully towards `ruff` instead of `black`.
  221. ### Changelog
  222. - 2.2.0 April 14, 2025
  223. - Updated user agents file (JSONL)
  224. - Updated dependencies
  225. - Python 3.8 support is officially dropped
  226. - Python 3.11 support is added
  227. - Improved `pyproject.toml` file
  228. - 2.1.0 March 12, 2025
  229. - Speed up the UA converter script and add it to workflow via cronjob
  230. - Dump up dependencies versions
  231. - Updated user agents file (JSONB)
  232. - Improved safe attrs checker and added `shape` as safe attr by default (for IDE).
  233. - 2.0.2 & 2.0.3 December 10, 2024
  234. - Fix project dependencies toml file & sync docs
  235. - 2.0.1 December 7, 2024 (my birthday)
  236. - Add requires-python to toml config
  237. - 2.0.0 December 4, 2024
  238. - Switch to new data source (again again)
  239. - Possible browser options: `"Google", "Chrome", "Firefox", "Edge", "Opera", "Safari", "Android", "Yandex Browser", "Samsung Internet", "Opera Mobile",
  240. "Mobile Safari", "Firefox Mobile", "Firefox iOS", "Chrome Mobile", "Chrome Mobile iOS", "Mobile Safari UI/WKWebView",
  241. "Edge Mobile", "DuckDuckGo Mobile", "MiuiBrowser", "Whale", "Twitter", "Facebook", "Amazon Silk"`
  242. - Possible OS options: `"Windows", "Linux", "Ubuntu", "Chrome OS", "Mac OS X", "Android", "iOS"`
  243. - Possible type options: `"desktop", "mobile", "tablet"`
  244. - Update fake.py to handle the new data key/value objects
  245. - Updated the README
  246. - Renamed browsers.json to browsers.jsonl. And other refactors.
  247. - 1.5.1 March 16, 2024
  248. - Remove trailing spaces in user agent strings
  249. - 1.5.0 March 8, 2024
  250. - Migrated to new user-agent data source (thanks @BoudewijnZwart), backwards compatible API.
  251. - Update all pip package dependencies to latest stable versions
  252. - 1.4.0 November 24, 2023
  253. - Update all PIP packages
  254. - Support Python 3.12 (thanks @vladkens)
  255. - Fix package conflict in cache scraper
  256. - Improve ruff CLI calls
  257. - 1.3.0 October 2, 2023
  258. - Introducing new `ua.getRandom`, `ua.getFirefox`, `ua.getChrome`, `ua.getSafari`. And a generic method: `ua.getBrowser(..)` (eg. `getBrowser('firefox')`)
  259. - These new properties above allows you to retrieve the whole raw Python dictionary, instead of only the UA string.
  260. - These properties might return different key/values pairs in the future!
  261. - Fix the `os` argument 'windows' to check for both `win10`and `win7` values (previously only checking on `win10`), thus returning more UAs
  262. - Improved user-agent scraper (now also containing Safari browser again)
  263. - Updated browsers.json data file
  264. - 1.2.1 August 2, 2023
  265. - Small improvements in the `min_percentage` check
  266. - Update all Pip package dependencies
  267. - 1.2.0 August 2, 2023
  268. - Updated browser useragent data
  269. - Allow filters on browser, OS and usage percentage
  270. - Update the cache scraper to scape the new data source for user-agent strings
  271. - Adapted the code to work with the new JSON data format
  272. - Parameter `use_external_data=True` and `verify_ssl` are **removed**. If you use those parameters, just remove it in your code!
  273. - 1.1.3 March 20, 2023
  274. - Update dependencies
  275. - 1.1.2 February 8, 2023
  276. - Security fixes
  277. - 1.1.1 December 4, 2022
  278. - Remove whitespaces from user agent strings, this is a patch release
  279. - 1.1.0 November 26, 2022
  280. - Add `pkg_resource` as fallback mechanism in trying to retrieve the local JSON data file
  281. - 1.0.1 November 10, 2022
  282. - Add `importlib-metadata` & `importlib-resources` as dependencies
  283. - Check on specific Python version regarding the importlib resources (python v3.10 or higher) in order to have `files()` working
  284. - `importlib_metadata` should now also work on Python version before 3.8
  285. - Remove obsolete `MANIFEST.in` file
  286. - 1.0.0 November 17, 2022
  287. - Make the JSON Lines data file part of the Python package, data is retrieved locally
  288. - Extend the `myproject.toml` file with `package-data` support
  289. - Remove centralized caching server implementation
  290. - Make real unit-tests which should run reliable, fast, independent and without Internet connection
  291. - 0.1.14 November 5, 2022
  292. - Improve code quality standards using modern Python >=3.7 syntax
  293. - Migrated to `pyproject.toml` build system format + syntax check
  294. - Add additional classifiers to the toml file
  295. - Improved `tox.ini` file
  296. - Improved GitHub Actions job using pip cache
  297. - And various small fixes
  298. - 0.1.13 October 21, 2022
  299. - Implement `browsers` argument, allowing you to override the browser names you want to use
  300. - Fix browser listing of Internet Explorer and Edge
  301. - Don't depend on w3schools.com anymore
  302. - Clean-up data (temp) file format
  303. - Update fallback cache server URL / use JSON Lines as file format
  304. - Move to GitHub Actions instead of Travis
  305. - Using [`black`](https://pypi.org/project/black/) Python formatter in favour of Flake
  306. - 0.1.12 March 31, 2022
  307. - forked
  308. - 0.1.11 October 4, 2018
  309. - moved `s3 + cloudfront` fallback to `heroku.com`, cuz someone from Florida did ~25M requests last month
  310. - 0.1.10 February 11, 2018
  311. - Minor fix docs `cloudfront` url
  312. - 0.1.9 February 11, 2018
  313. - fix `w3schools.com` renamed `IE/Edge` to `Edge/IE`
  314. - moved `heroku.com` fallback to `s3 + cloudfront`
  315. - stop testing Python3.3 and pypy
  316. - 0.1.8 November 2, 2017
  317. - fix `useragentstring.com` `Can't connect to local MySQL server through socket`
  318. - 0.1.7 April 2, 2017
  319. - fix broken README.rst
  320. - 0.1.6 April 2, 2017
  321. - fixes bug `use_cache_server` do not affected anything
  322. - `w3schools.com <https://www.w3schools.com/browsers/browsers_stats.asp>`\_ moved to `https`
  323. - `verify_ssl` options added, by default it is `True` (`urllib.urlopen` ssl context for Python 2.7.9- and 3.4.3- is not supported)
  324. - 0.1.5 February 28, 2017
  325. - added `ua.edge` alias to Internet Explorer
  326. - w3schools.com starts displaying `Edge` statistic
  327. - Python 2.6 is not tested anymore
  328. - `use_cache_server` option added
  329. - Increased `fake_useragent.settings.HTTP_TIMEOUT` to 5 seconds
  330. - 0.1.4 December 14, 2016
  331. - Added custom data file location support
  332. - Added `fallback` browser support, in case of unavailable data sources
  333. - Added alias `fake_useragent.FakeUserAgent` for `fake_useragent.UserAgent`
  334. - Added alias `fake_useragent.UserAgentError` for `fake_useragent.FakeUserAgentError`
  335. - Reduced `fake_useragent.settings.HTTP_TIMEOUT` to 3 seconds
  336. - Started migration to new data file format
  337. - Simplified a lot 4+ years out of date code
  338. - Better thread/greenlet safety
  339. - Added verbose logging
  340. - Added `safe_attrs` for prevent overriding by `__getattr__`
  341. - 0.1.3 November 24, 2016
  342. - Added hosted data file, when remote services is unavailable
  343. - Raises `fake_useragent.errors.FakeUserAgentError` in case when there is not way to download data
  344. - Raises `fake_useragent.errors.FakeUserAgentError` instead of `None` in case of unknown browser
  345. - Added `gevent.sleep` support in `gevent` patched environment when trying to download data
  346. - X.X.X xxxxxxx xx, xxxx
  347. - xxxxx ?????
  348. ### Authors
  349. You can visit [authors page](https://github.com/fake-useragent/fake-useragent/blob/main/AUTHORS).