pyrua
Professional Random User-Agent Generator for Python
A comprehensive, lightweight Python module for generating realistic User-Agent strings for web scraping, testing, and browser simulation. Supports all major browsers, operating systems, and device types.
Features
- Multiple Browsers: Chrome, Firefox, Safari, Edge, Opera, Brave
- All Platforms: Windows, macOS, Linux, Android, iOS
- Device Types: Desktop, Mobile, Tablet
- Customizable: Filter by browser, OS, or device type
- Realistic Distribution:
get_common_ua()mimics real-world browser market share - Bulk Generation: Generate lists of unique User-Agents
- Zero Dependencies: Pure Python, no external packages required
- Type Hints: Full typing support for modern IDEs
- Python 3.8+: Supports all modern Python versions
Installation
pip install pyrua
Quick Start
Basic Usage
from pyrua import get_rua
# Generate a random User-Agent
user_agent = get_rua()
print(user_agent)
# Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.109 Safari/537.36
Browser-Specific User-Agents
from pyrua import get_chrome_ua, get_firefox_ua, get_safari_ua, get_edge_ua, get_opera_ua
# Chrome User-Agent
chrome_ua = get_chrome_ua()
# Firefox User-Agent
firefox_ua = get_firefox_ua()
# Safari User-Agent
safari_ua = get_safari_ua()
# Edge User-Agent
edge_ua = get_edge_ua()
# Opera User-Agent
opera_ua = get_opera_ua()
Device-Specific User-Agents
from pyrua import get_desktop_ua, get_mobile_ua, get_android_ua, get_ios_ua
# Desktop User-Agent (random browser/OS)
desktop_ua = get_desktop_ua()
# Mobile User-Agent (Android or iOS)
mobile_ua = get_mobile_ua()
# Android-specific
android_ua = get_android_ua()
# iOS-specific (iPhone/iPad)
ios_ua = get_ios_ua()
Advanced Customization
from pyrua import get_ua, Browser, OS, DeviceType
# Chrome on Windows
ua = get_ua(browser=Browser.CHROME, os_type=OS.WINDOWS)
# Firefox on macOS
ua = get_ua(browser=Browser.FIREFOX, os_type=OS.MACOS)
# Any mobile User-Agent
ua = get_ua(device_type=DeviceType.MOBILE)
# Safari on iOS
ua = get_ua(browser=Browser.SAFARI, os_type=OS.IOS)
# Chrome on Android
ua = get_ua(browser=Browser.CHROME, os_type=OS.ANDROID)
Bulk Generation
from pyrua import get_rua_list
# Generate 10 unique random User-Agents
ua_list = get_rua_list(count=10, unique=True)
for ua in ua_list:
print(ua)
Realistic Distribution
from pyrua import get_common_ua
# Generate User-Agent based on real-world browser market share
# (Chrome ~65%, Safari ~18%, Edge ~5%, Firefox ~3%, etc.)
common_ua = get_common_ua()
🛠️ Use Cases
Web Scraping with Requests
import requests
from pyrua import get_rua
headers = {
'User-Agent': get_rua()
}
response = requests.get('https://example.com', headers=headers)
Selenium WebDriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from pyrua import get_chrome_ua
options = Options()
options.add_argument(f'user-agent={get_chrome_ua()}')
driver = webdriver.Chrome(options=options)
aiohttp Async Requests
import aiohttp
from pyrua import get_rua
async def fetch(url):
async with aiohttp.ClientSession() as session:
headers = {'User-Agent': get_rua()}
async with session.get(url, headers=headers) as response:
return await response.text()
httpx Client
import httpx
from pyrua import get_rua
client = httpx.Client(headers={'User-Agent': get_rua()})
response = client.get('https://example.com')
Rotating User-Agents
from pyrua import get_rua_list
# Pre-generate a pool of User-Agents
ua_pool = get_rua_list(count=100, unique=True)
# Use in rotation
import itertools
ua_cycle = itertools.cycle(ua_pool)
for url in urls:
headers = {'User-Agent': next(ua_cycle)}
# ... make request
API Reference
Core Functions
| Function | Description |
|---|---|
get_rua() |
Random User-Agent from any browser/device |
get_ua(browser, os_type, device_type) |
Customizable User-Agent generation |
get_rua_list(count, unique) |
Generate multiple User-Agents |
get_common_ua() |
User-Agent based on market share distribution |
Browser-Specific Functions
| Function | Description |
|---|---|
get_chrome_ua(os_type) |
Chrome User-Agent |
get_firefox_ua(os_type) |
Firefox User-Agent |
get_safari_ua() |
Safari User-Agent (macOS) |
get_edge_ua(os_type) |
Microsoft Edge User-Agent |
get_opera_ua(os_type) |
Opera User-Agent |
Device-Specific Functions
| Function | Description |
|---|---|
get_desktop_ua(browser, os_type) |
Desktop User-Agent |
get_mobile_ua() |
Mobile User-Agent (Android/iOS) |
get_android_ua(browser) |
Android User-Agent |
get_ios_ua(browser) |
iOS User-Agent (iPhone/iPad) |
Enums
from pyrua import Browser, OS, DeviceType
# Browser options
Browser.CHROME, Browser.FIREFOX, Browser.SAFARI, Browser.EDGE, Browser.OPERA, Browser.BRAVE
# OS options
OS.WINDOWS, OS.MACOS, OS.LINUX, OS.ANDROID, OS.IOS
# Device types
DeviceType.DESKTOP, DeviceType.MOBILE, DeviceType.TABLET
Migration from v0.x
If you're upgrading from the original version, the get_rua() function still works but now returns modern browser User-Agents. For the original Samsung Bada User-Agent, use:
from pyrua import get_legacy_ua
legacy_ua = get_legacy_ua()
🤝 Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone the repository
git clone https://github.com/farhaanaliii/pyrua.git
cd pyrua
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black pyrua/
isort pyrua/
# Type checking
mypy pyrua/
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Inspired by the need for realistic User-Agent strings in web scraping projects
- Browser version data sourced from real-world browser release information
Contact
- Author: Farhan Ali
- GitHub: @farhaanaliii
- Project Link: https://github.com/farhaanaliii/pyrua
⭐ If you find this project useful, please consider giving it a star on GitHub!
Release files for pyrua 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyrua-1.0.0.tar.gz | 18.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyrua-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.1 kB
Release files / pyrua-1.0.0.tar.gz
| Download URL | pyrua-1.0.0.tar.gz |
|---|---|
| Size | 18.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b6ebed5858be8ad04aaef4ac0c11e942b0bb41c6df3c28c26672a71570fee20
|
|
BLAKE2b-256 checksum How to use checksums |
3081b0e1963088812db0a67b176f42b6b10b2e27aeb7eafed928e48f0aba47d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.1
|
Release files / pyrua-1.0.0-py3-none-any.whl
| Download URL | pyrua-1.0.0-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0662316a5ae24318a7cc2e4269f1796f3bedcca358e32e158c424cfd70336d3
|
|
BLAKE2b-256 checksum How to use checksums |
4c524ee174266eb01275a2b907bebc815c623208b7912c34e0d4a61595575b60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.1
|