Skip to main content
Application Banner

Fetches real world, up-to-date user agents for use in web scraping to avoid bot detection. No more fake or outdated user agents, only user agents of real users. You can either get random or usage-weighted user agents. It caches the user agents locally to avoid unnecessary API calls, and refreshes them automatically every 24 hours from the public API of useragents.me. If you need full-fledge fake browser headers including client hints like sec-ch-ua, sec-fetch-site and more, check out my simple-header package.

Donate BuyMeACoffee

 

Contents

 

Features

  • Up-to-date: No fake or outdated user agents. Only real world data, refreshed every 24 hours.
  • Wide Support: User Agents for Windows, macOS, Linux, Android and iOS devices: Google Chrome, Firefox, Safari, Edge, Opera, Whale and QQ browsers.
  • Lightweight: Caches user agents locally to consume minimal system resources.
  • Simple: Easy to use and understand with a clean and simple API.
  • Compatible: Supports Python 3.8 and above. Runs on Windows, macOS and Linux.
  • Tested: Has 99% test coverage and is continuously tested.
  • Privacy: Protects the user by not collecting or sending any personal data.
  • Open Source: Provides transparency and allows community contributions for continuous development.

 

Installation

Just install the package from PyPi using pip:

pip install simple-useragent

 

Usage

Quickstart

Just import the package and use the convenience functions. For more advanced usage, you can initialize the class to set custom settings.

import simple_useragent as sua

sua.get(num=2, mobile=True)  # List of the 2 most common mobile user agents (attributes explained below).
# [UserAgent('Mozilla/5.0 (Android ...'), UserAgent('Mozilla/5.0 (iPhone; ...')]

sua.get_list(shuffle=True, force_cached=True)  # Random list of available desktop user agents strings.
# ['Mozilla/5.0 ...', 'Mozilla/5.0 (iPhone ...', 'Mozilla/5.0 (iPhone ...', ...]

sua.get_dict()  # Dictionary with all desktop and mobile user agents.
# {'desktop': ['Mozilla/5.0 ...', ...] 'mobile': ['Mozilla/5.0 (iPhone ...', ...]}

 

Advanced Usage

Import the package and initialize the UserAgents class to set custom settings (optional, see Settings and Parameters for details).

import simple_useragent as sua

simple_ua = sua.UserAgents(max_retries=3, timeout=5, cache_duration=86400, cache_location='example/path/to/folder')

 

Fetching User Agents.

# Fetch a specified number of random mobile user agent instances (with settings from the class above).
simple_ua.get(num=2, shuffle=True, mobile=True)
# [UserAgent('Mozilla/5.0 (iPhone ...'), UserAgent('Mozilla/5.0 (iPhone; ...')]

 

You can also use the convenience functions to get user agents without initializing the class.

sua.get(num=2, mobile=True)  # List of the 2 most common mobile user agent (attributes explained below).
# [UserAgent('Mozilla/5.0 (Android ...'), UserAgent('Mozilla/5.0 (iPhone; ...')]

sua.get_list(force_cached=True)  # List of all available desktop user agents as strings.
# ['Mozilla/5.0 ...', 'Mozilla/5.0 (iPhone ...', 'Mozilla/5.0 (iPhone ...', ...]

sua.get_dict()  # Dictionary with all desktop and mobile user agents.
# {'desktop': ['Mozilla/5.0 ...', ...] 'mobile': ['Mozilla/5.0 (iPhone ...', ...]}

 

The instance offers attributes for the user agent properties.

# Parse a custom string directly to the UserAgent class and access its attributes.
obj = sua.parse('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36')
obj.string  # 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit ...'
obj.browser  # 'Chrome', 'Firefox', 'Safari', 'Edge', 'IE', 'Opera', 'Whale', 'QQ Browser', 'Samsung Browser', 'Other'
obj.browser_version  # '110', '109', '537', ...
obj.browser_version_minor  # '0', '1', '36', ...

# You can also access the attributes with square brackets.
obj = sua.get(num=1, shuffle=True)[0]
obj['os']  # 'Windows', 'macOS', 'Linux', 'Android', 'iOS', 'Other'
obj['os_version']  # '10', '7', '11', '14', ...
obj['os_version_minor']  # '0', '1', '2', ...
obj['mobile']  # True / False

 

Settings and Parameters

The functions can take the following parameters:

  • num: The number of user agents to fetch (default: None = gets you all user agents available).
  • mobile: Fetch mobile or desktop user agents (default: False = desktop).
  • shuffle: Whether to shuffle/randomize the order of user agents (default: False = ordered by usage).
  • force_cached: Force the use of memory or file cached user agents (default: None = fetches new user agents if cache is outdated, False = always call the API, True = always use the cache).

 

You can set custom preferences when initializing the class with UserAgents(...).

  • max_retries: The maximum number of retries to reach the API, before falling back to local cache (default: 3).
  • timeout: The timeout in seconds for the API request (default: 5).
  • cache_duration: The duration in seconds for the user agents to be cached (default: 86400 = 1 day).
  • cache_location: The folder in which the user agents are cached, specific to the OS. You can see the default location with UserAgents._cache_location.

 

Notes:

  • The user agents are cached locally to avoid unnecessary API calls, and are refreshed automatically every 24 hours.
  • During runtime the user agents are stored in memory and written to a cache file for persistence and performance.
  • Every time you invoke a simple-useragent function, it is automatically checked for outdated user agents.

 

Development

As an open-source project, I strive for transparency and collaboration in my development process. I greatly appreciate any contributions members of our community can provide. Whether you are fixing bugs, proposing features, improving documentation, or spreading awareness - your involvement strengthens the project. Please review the code of conduct to understand how we work together respectfully.

 

Contributors

Thank you so much for giving feedback, implementing features and improving the code and project!

Contributors

 

Credits

Full credits are in the ACKNOWLEDGMENTS file.

 

License

Provided under the terms of the GNU GPL3 License © Lennart Haack 2024.

See LICENSE file for details. For the licenses of used third party libraries and software, please refer to the ACKNOWLEDGMENTS file.

Metadata

Release files for simple-useragent 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-useragent 0.1.6
File Size Uploaded Provenance Actions
simple_useragent-0.1.6.tar.gz 31.3 kB Without provenance Details for simple_useragent-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simple-useragent 0.1.6
File Interpreter ABI Platform Actions
simple_useragent-0.1.6-py3-none-any.whl Python 3 none any Details for simple_useragent-0.1.6-py3-none-any.whl

Total release size: 58.8 kB

Release files / simple_useragent-0.1.6.tar.gz

Download URL simple_useragent-0.1.6.tar.gz
Size 31.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b36fe56f26da76173efd0dcc49dd960a9dc8ac70169dccbaef3f982746ec7cb7
BLAKE2b-256 checksum
How to use checksums
bb9f3f81291395045d0be4fff3568ec943e5838141034fbc68145f7f4369dbcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.19

Release files / simple_useragent-0.1.6-py3-none-any.whl

Download URL simple_useragent-0.1.6-py3-none-any.whl
Size 27.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3427dd672e41ebc52d4920219f03cddac19ee23e5098cdd49e771a67587b798e
BLAKE2b-256 checksum
How to use checksums
80a6fff61903cd2ba383367fbd30bbcea87f4ceed32b67a312fb4beb4a8bb6ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.19

Security for simple-useragent 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page