Skip to main content

Randomly generate a fake useragent.

This project's idea is inspired by fake-useragent. I rewrote the whole codes in order to boost performance by:

  • using asyncio and aiohttp to improve fetching speed
  • taking advantage of Xpath to improve parsing speed
  • changing random choice algorithm to improve random choice speed

Supported browsers are: chrome, edge, firefox, safari, and opera. Browser name is case insensitive. Some other possible spellings of each browser are mapped to the right one (e.g. "ie" -> "edge", "google" -> "chrome").

Usage

On your terminal, just simply enter fakeua

In your python script, just import the function. Every time you run the script, the useragent value will be different.

from fake_user_agent import user_agent

# Not specify a browser:
ua = user_agent()

# Specify a browser to randomly choose from:
ua = user_agent("chrome")

# It takes < 2s for the first run based on my 200M bandwith, including fetching, parsing, and writing cache. 
# Using tempfile by default, it takes < 0.01s starting from the second time. 
# You can specify not using tempfile, and it will take < 1s to run, including fetching and parsing:
ua = user_agent(use_tempfile=False)

# If there is an async function needing a useragent in your script,
# don't put `user_agent()` in your async function, put it above instead.

# Remove tempfile in a python script. 
# May need `sudo python yourscript.py` for Linux.
from fake_user_agent import rm_tempfile
rm_tempfile()  

Other usages on terminal

# Set to get a useragent in debug mode
fakeua <browser or omit> --debug

# Set to get a useragent without local caching
fakeua <browser or omit> --nocache

# Remove cache from tempfile folder
fakeua --remove  

# Print the current version of the program
fakeua --version

Installation

pip install fake_user_agent

Metadata

Release files for fake_user_agent 2.0.7

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

Source distribution (sdist)

Source distribution for fake_user_agent 2.0.7
File Size Uploaded
fake_user_agent-2.0.7.tar.gz 145.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fake_user_agent 2.0.7
File Interpreter ABI Platform
fake_user_agent-2.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 152.9 kB

Release files / fake_user_agent-2.0.7.tar.gz

Download URL fake_user_agent-2.0.7.tar.gz
Size 145.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ca00ec05b09649de5626fc18fe6b2672536c023adccf5a6cc23004495dbcc73d
BLAKE2b-256 checksum
How to use checksums
77c9b97afd2d14d33d9f1481fd26654b7162987f230a1b32b7d2e5fdfb2d2d93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release files / fake_user_agent-2.0.7-py3-none-any.whl

Download URL fake_user_agent-2.0.7-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad5617877cb2de2a0d5490a2714c54084c9cdde48129e45e617e7d5ff63bc7fc
BLAKE2b-256 checksum
How to use checksums
7924b272cc8c6f9fd8682a5448bf73a725b28af4ae3265b2f6fa223edee94dab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release history Release notifications | RSS feed

2.3.9

2 release files

2.2.0

2 release files

2.1.9

2 release files

2.1.8

2 release files

2.1.7

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

This release

2.0.7 This release

2 release files

2.0.6

2 release files

2.0.5

1 release file

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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