Registry / http-networking / random-user-agent

random-user-agent

JSON →
library1.0.1pypypi✓ verified 89d ago

This Python library provides lists of user agents based on filters such as operating system, software name, and popularity. It currently holds a collection of over 326,000 user agents. The library's last release was version 1.0.1 in December 2018, making its user agent data significantly outdated for modern web scraping and automation tasks.

pip install random_user_agent
INSTALL
IMPORT
SIG · RANDOM-USER-AGENT
R
random-user-agent
http-networkingpythonv1.0.1
Install
1.6s avg
Import
32ms
Disk
24MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.033s · 25.7MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.031s · 26MB
24MB installed
● package 24MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

UserAgent
✓ from random_user_agent.user_agent import UserAgent
SoftwareName, OperatingSystem
✓ from random_user_agent.params import SoftwareName, OperatingSystem

This quickstart demonstrates how to import the UserAgent class and parameter enums, initialize a user agent rotator with specific browser and operating system filters, retrieve a list of user agents, and get a single random user agent.

from random_user_agent.user_agent import UserAgent from random_user_agent.params import SoftwareName, OperatingSystem # Define desired filters software_names = [SoftwareName.CHROME.value, SoftwareName.FIREFOX.value] operating_systems = [OperatingSystem.WINDOWS.value, OperatingSystem.LINUX.value] # Initialize the UserAgent rotator with filters and a limit user_agent_rotator = UserAgent( software_names=software_names, operating_systems=operating_systems, limit=10 # Get 10 random user agents ) # Get a list of user agents user_agents = user_agent_rotator.get_user_agents() # Print some user agents for i, ua in enumerate(user_agents[:3]): print(f"User Agent {i+1}: {ua}") # Get a single random user agent single_ua = user_agent_rotator.get_random_user_agent() print(f"\nSingle Random User Agent: {single_ua}")
Debug
Known issues
breakingThe library has not been updated since December 2018. As user agent strings evolve rapidly with new browser and OS versions, the data provided by this library is severely outdated. Using these old user agents in modern web scraping or automation tasks is highly likely to lead to detection or incorrect rendering.
fix
Consider using actively maintained libraries like 'fake-useragent' or 'ua-generator' that provide up-to-date user agent lists or dynamically generate them. Always verify the recency of user agent data if using any random user agent generator.
affects: 1.0.1 and earlier
gotchaThe project is no longer actively maintained, with the last commit dating back to 2018. This means there will be no bug fixes, feature updates, or updates to its internal user agent database, which is crucial for the utility of such a library.
fix
Assess the critical need for up-to-date user agents. If your application relies on current browser and OS identities, this library is unsuitable. Migrate to a well-maintained alternative.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'random_user_agent'
The `random-user-agent` package is not installed in the current Python environment or there is a typo in the package name during import.
fix
Install the library using pip: `pip install random-user-agent`
ImportError: cannot import name 'UserAgent' from 'random_user_agent'
The `UserAgent` class is located within the `user_agent` submodule, not directly in the top-level `random_user_agent` package.
fix
Import the `UserAgent` class from its correct submodule path: `from random_user_agent.user_agent import UserAgent`
AttributeError: module 'random_user_agent' has no attribute 'get_random_user_agent'
The `get_random_user_agent` method is part of an instance of the `UserAgent` class, not a function directly available on the `random_user_agent` module.
fix
First, import and instantiate the `UserAgent` class, then call the method on the instance:
```python
from random_user_agent.user_agent import UserAgent

ua_rotator = UserAgent()
user_agent = ua_rotator.get_random_user_agent()
```
IndexError: list index out of range
This error occurs when `get_random_user_agent()` is called after applying filters (e.g., `software_names`, `operating_systems`) that result in an empty list of matching user agents. This can be due to overly restrictive criteria or incorrectly passing enum objects directly instead of their `.value`.
fix
Ensure filter values are correct (e.g., use `SoftwareName.CHROME.value`), broaden the filters to ensure a non-empty list, or add a check before calling `get_random_user_agent()`:
```python
from random_user_agent.user_agent import UserAgent
from random_user_agent.params import SoftwareName, OperatingSystem

user_agent_rotator = UserAgent(
    software_names=[SoftwareName.CHROME.value], # Use .value for enum values
    operating_systems=[OperatingSystem.WINDOWS.value]
)

# Add a check to prevent IndexError
if user_agent_rotator.user_agents_list:
    user_agent = user_agent_rotator.get_random_user_agent()
else:
    print("No user agents found with the specified filters.")
```
Upgrade
Version history
1.0.1latest on PyPI · released Dec 26, 2018
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
random-user-agent — pip install random-user-agent · libregistry