User-Agent API Reference¶
Auto-generated API documentation for the User-Agent generator module.
useragent
¶
Lightweight User-Agent generator for Chrome/Edge with Client Hints.
Part of zerodep: https://github.com/Oaklight/zerodep Copyright (c) 2026 Peng Ding. MIT License.
Generates realistic browser UA strings and matching Sec-CH-UA-* headers.
Covers Windows, macOS, Linux (desktop) and Android (mobile) platforms with
Chrome and Edge browsers only -- this is intentionally minimal.
Inspired by ua-generator <https://github.com/iamdual/ua-generator>_ (Apache-2.0).
Zero external dependencies -- stdlib random only.
Basic usage::
from useragent import generate
ua = generate(browser="chrome", device="desktop")
print(ua.text) # full User-Agent string
print(ua.headers.get()) # dict with UA + Client Hints headers
UserAgent
¶
A generated user-agent with matching Client Hints headers.
Attributes:
| Name | Type | Description |
|---|---|---|
browser |
Browser name ( |
|
platform |
Platform name ( |
|
version |
4-tuple |
|
text |
The full User-Agent string. |
|
headers |
A :class: |
Example::
ua = generate(browser=["chrome", "edge"])
ua.headers.accept_ch("Sec-CH-UA-Platform-Version")
headers = ua.headers.get()
Source code in useragent/useragent.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
generate(*, browser=None, device=None)
¶
Generate a random User-Agent with matching Client Hints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
browser
|
Union[str, Sequence[str]] | None
|
Browser name or list of names to pick from.
Supported: |
None
|
device
|
str | None
|
Device type -- |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
UserAgent
|
class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If browser is not |