Skip to main content

rand-useragent

An up-to-date simple random user-agent with real world database. The collections of user-agent data is pre-downloaded from techblog.willshouse.com.

Installation

$ pip install rand-useragent

Usage

Simple usage example, see below for more examples:

from rand_useragent import randua

# Get a random browser user-agent string
print(randua())

If you want to specify your own browser list, you can do that via the browsers argument (default is: ["chrome", "edge", "firefox", "safari"]).
This example will only return random useragents from Edge and Chrome:

from rand_useragent import randua

# Get a random browser user-agent string
print(randua(browsers=["edge", "chrome"]))

If you want to specify your own operating systems, you can do that via the os argument (default is: ["windows", "mac os x", "linux"]).
In this example you will only get Linux useragents back:

from rand_useragent import randua

# Get a random browser user-agent string
print(randua(os=["linux"]))

If you want to return more popular useragent strings, you can play with the min_percent argument (default is: 0.0, meaning all useragents will match).
In this example you get only useragents that have a minimum usage percentage of 10.0% (or higher):

from rand_useragent import randua

# Get a random browser user-agent string
print(randua(min_percent=10.0))

You can override the fallback string using the fallback parameter, in very rare cases something failed:

from rand_useragent import randua

# If something went wrong
print(
    randua(
        fallback="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
    )
)

Development

Since GitHub Actions is unable to reach willshouse.com and has Cloudflare protection. We can run the script below to automatically scrape the user-agent strings from the external data source. The script will copy the JSONlines file to the src/rand_useragent/data directory. Execute:

$ ./scripts/update-data.sh

The data JSON file is part of the Python package, see pyproject.toml. Read more about Data files support.


rand-useragent is a BSD licensed code.

Metadata

Release files for rand-useragent 0.2.0

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

Source distribution (sdist)

Source distribution for rand-useragent 0.2.0
File Size Uploaded
rand-useragent-0.2.0.tar.gz 9.1 kB Details

Release files / rand-useragent-0.2.0.tar.gz

Download URL rand-useragent-0.2.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
19aa788e7007c4c8f9d8853707c2ea3d7230b56b3303e8e75992af18fcc92169
BLAKE2b-256 checksum
How to use checksums
3cecf952de0d96f4a8282e85d01e61fc98a363477bf4a6da5cabdd7531c8aa93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.29.0 requests-toolbelt/0.9.1 tqdm/4.65.0 CPython/3.10.9

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

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