ua-generator
A random user-agent generator for Python >= 3.9
Features
- No dependency.
- No external user-agent list, no downloads.
- User-agent versions are hardcoded into the code.
- Platform and browser versions are based on real releases.
- Client Hints (Sec-CH-UA fields).
- Easy to integrate into HTTP libraries.
Install & upgrade
pip install -U ua-generator
Note: Upgrade ua-generator periodically to keep user-agent versions up to date.
Basic usage
import ua_generator
ua = ua_generator.generate()
print(ua) # Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/15.2 Safari/604.1.38
Customization
It takes three different parameters to customize the user-agent.
device = ['desktop', 'mobile']
platform = ['windows', 'macos', 'ios', 'linux', 'android']
browser = ['chrome', 'edge', 'firefox', 'safari']
Note: All parameters are optional and multiple types can be specified using a list (or tuple).
Customized user-agent generation:
import ua_generator
# Example 1:
ua = ua_generator.generate(device='desktop', browser=['chrome', 'edge'])
print(ua.text) # Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
print(ua.platform) # windows
print(ua.browser) # chrome
print(ua.ch.brands) # "Not A(Brand";v="99", "Chromium";v="129", "Google Chrome";v="129"
print(ua.ch.brands_full_version_list) # "Not A(Brand";v="99.0.0.0", "Chromium";v="129.0.6668.116", "Google Chrome";v="129.0.6668.116"
print(ua.ch.mobile) # ?0
print(ua.ch.platform) # "Windows"
print(ua.ch.platform_version) # "13.0.0"
print(ua.ch.browser_version) # "129"
print(ua.ch.browser_full_version) # "129.0.6668.116"
print(ua.ch.bitness) # "64"
print(ua.ch.architecture) # "x86"
print(ua.ch.wow64) # "?1"
# Example 2:
ua = ua_generator.generate(platform=['ios', 'macos'], browser='edge')
print(ua.text) # Mozilla/5.0 (iPhone; CPU iPhone OS 18_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) EdgiOS/117.0.2045.73 Version/18.0 Mobile/15E148 Safari/604.1
print(ua.platform) # ios
print(ua.browser) # edge
print(ua.ch.brands) # "Not A(Brand";v="99", "Chromium";v="117", "Microsoft Edge";v="117"
print(ua.ch.brands_full_version_list) # "Not A(Brand";v="99.0.0.0", "Chromium";v="117.0.2045.73", "Microsoft Edge";v="117.0.2045.73"
print(ua.ch.mobile) # ?1
print(ua.ch.platform) # "iOS"
print(ua.ch.platform_version) # "18.6.1"
print(ua.ch.browser_version) # "117"
print(ua.ch.browser_full_version) # "117.0.2045.73"
print(ua.ch.bitness) # "64"
print(ua.ch.architecture) # arm
print(ua.ch.wow64) # ?0
Headers
ua = ua_generator.generate(browser=['chrome', 'edge'])
# This will return a dictionary containing the generated user-agent:
print(ua.headers.get())
{
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.43 Safari/537.36',
'sec-ch-ua': '"Not A(Brand";v="99", "Chromium";v="103", "Google Chrome";v="103"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"'
}
# Extending the "Client Hints" by a value of the "Accept-CH" header:
ua.headers.accept_ch('Sec-CH-UA-Platform-Version, Sec-CH-UA-Full-Version-List')
print(ua.headers.get())
{
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.94 Safari/537.36',
'sec-ch-ua': '"Not A(Brand";v="99", "Chromium";v="122", "Google Chrome";v="122"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"',
'sec-ch-ua-platform-version': '"14.1.0"',
'sec-ch-ua-full-version-list': '"Not A(Brand";v="99.0.0.0", "Chromium";v="122.0.6261.94", "Google Chrome";v="122.0.6261.94"'
}
Integrating into the requests:
import requests
import ua_generator
ua = ua_generator.generate(browser=['chrome', 'edge'])
r = requests.get('https://httpbin.org/get', headers=ua.headers.get())
Integrating into the httpx:
import httpx
import ua_generator
ua = ua_generator.generate(browser=['chrome', 'edge'])
r = httpx.get('https://httpbin.org/get', headers=ua.headers.get())
Integrating into the urllib:
import urllib.request
import ua_generator
ua = ua_generator.generate(browser=['chrome', 'edge'])
request = urllib.request.Request('https://httpbin.org/get', headers=ua.headers.get())
handler = urllib.request.urlopen(request)
response = handler.read().decode('utf-8')
Integrating into the Selenium:
import time
from selenium import webdriver
import ua_generator
ua = ua_generator.generate(browser=['chrome', 'edge'], device=['desktop'])
driver = webdriver.Chrome()
driver.execute_cdp_cmd('Network.setExtraHTTPHeaders', {'headers': ua.headers.get()})
driver.execute_cdp_cmd('Network.setUserAgentOverride', {
'userAgent': ua.text,
'userAgentMetadata': ua.navigator.get()
})
driver.get('https://browserleaks.com/client-hints')
time.sleep(1000)
Options
You can define options using the "options" parameter for further customization.
weighted_versions
To increase the probability of the latest versions being chosen. Default is False.
import ua_generator
from ua_generator.options import Options
# Enabling weighted versions
options = Options()
options.weighted_versions = True
ua = ua_generator.generate(browser=['chrome', 'edge'], options=options)
version_ranges
To choose only versions within specified ranges. Default is None.
import ua_generator
from ua_generator.options import Options
from ua_generator.data.version import Version, VersionRange
# Choosing only versions within specified ranges
options = Options()
options.version_ranges = {
'chrome': VersionRange(125, 129), # Choose version between 125 and 129
'edge': VersionRange(min_version=120), # Choose version 120 minimum
'macos': VersionRange(max_version=Version(10, 15, 7)), # Choose macOS 10.15.7 maximum
}
ua = ua_generator.generate(browser='chrome', options=options)
Note: If there is no valid version within the range you set, the filter will just skip it and return a random valid version instead.
latest_versions
To choose only the latest version, or one of the latest N versions for specified browsers or platforms. Default is False.
import ua_generator
from ua_generator.options import Options
# Choose only the latest version for every browser and platform
options = Options()
options.latest_versions = True
ua = ua_generator.generate(options=options)
# Choose one of the latest N versions for specified browsers and platforms
options = Options()
options.latest_versions = {
'chrome': 3,
'firefox': 1,
'ios': 3,
'macos': 1,
}
ua = ua_generator.generate(browser='chrome', platform='ios', options=options)
tied_safari_version
To make Safari version tied to macOS/iOS version. Default is False.
Issues
You can create an issue from here if you are experiencing a problem.
Contributing
Pull requests are welcome. Don't forget to run tests.
Contributors
Ekin Karadeniz (@iamdual) and the GitHub community.
Metadata
Release files for ua-generator 2.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ua_generator-2.1.4.tar.gz | 29.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ua_generator-2.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.6 kB
Release files / ua_generator-2.1.4.tar.gz
| Download URL | ua_generator-2.1.4.tar.gz |
|---|---|
| Size | 29.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3936b8cc87e04eddaab053104d2cac163e14cce8dc2ba7a02639c213e8dff57
|
|
BLAKE2b-256 checksum How to use checksums |
8696fef4aa75300f07c90d5eaaeb3d946cf8d523513c4831563325fe29e321c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.
Transparency logRelease files / ua_generator-2.1.4-py3-none-any.whl
| Download URL | ua_generator-2.1.4-py3-none-any.whl |
|---|---|
| Size | 32.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
822606a308f1097ce299ed6f26fc90c3377da44861f5a9d41c6529390b3df1d5
|
|
BLAKE2b-256 checksum How to use checksums |
6bebc3305fab3fbed08512b5bb058be67f1943e5ca732945b4d1f3efc82b3768
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.
Transparency log