Registry / http-networking / latest-user-agents

latest-user-agents

JSON →
library0.0.5pypypiunverified

`latest-user-agents` is a Python library (version 0.0.5) that provides a simple function to retrieve a list of up-to-date user agent strings for major browsers and operating systems. It fetches these lists dynamically from an external website, caches them, and makes them available for use in web scraping or testing. The project is in maintenance, with no recent updates, but its core functionality remains stable.

pip install latest-user-agents requests
INSTALL
IMPORT
SIG · LATEST-USER-AGENTS
L
latest-user-agents
http-networkingpythonv0.0.5
Install
3.9s avg
Import
603ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.634s · 21.5MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.9s · import 0.571s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_latest_user_agents
from latest_user_agents import get_latest_user_agents

Fetches a list of current user agent strings and demonstrates selecting a random one. It includes a check for an empty list, which can occur if the external source is unavailable. Note that `requests` is implicitly required for internal fetching and explicitly for the example.

import random from latest_user_agents import get_latest_user_agents # Get a list of the latest user agents user_agents = get_latest_user_agents() if user_agents: # Select a random user agent from the list random_ua = random.choice(user_agents) print(f"Total user agents fetched: {len(user_agents)}") print(f"Random user agent: {random_ua}") # Example of using it with requests (requires 'requests' to be installed) # import requests # try: # response = requests.get('http://httpbin.org/user-agent', headers={'User-Agent': random_ua}) # response.raise_for_status() # print(f"Response from httpbin: {response.json()}") # except Exception as e: # print(f"Error fetching from httpbin: {e}") else: print("Could not fetch user agents. The list is empty.")
Debug
Known issues
gotchaThe library implicitly depends on the `requests` package but does not declare it as a dependency in its `setup.py`. Without `requests` installed, the library will raise a `ModuleNotFoundError` when attempting to fetch user agents.
fix
Ensure `requests` is installed alongside `latest-user-agents` by running `pip install latest-user-agents requests`.
affects: 0.0.1 - 0.0.5
gotchaUser agent lists are fetched dynamically from `useragents.me`. If this external service is unavailable, changes its HTML structure, or blocks requests, the library will fail to retrieve new user agents, potentially returning an empty list or raising an error.
fix
Verify the availability of `useragents.me` or consider a different user agent source if reliability is critical. The library does not provide built-in fallbacks and may return an empty list upon failure.
affects: 0.0.1 - 0.0.5
gotchaThe library caches the fetched user agent list to avoid repeated network requests. However, the cache has a default expiry of 24 hours. For rapidly changing user agent needs, or if the source data updates more frequently, you might receive slightly stale data.
fix
The library does not expose a way to manually clear the cache or adjust the expiry via its public API. If fresher data is required before the 24-hour expiry, you might need to restart your application or consider a workaround.
affects: 0.0.1 - 0.0.5
Upgrade
Version history
0.0.5latest on PyPI · released Jan 24, 2025
Audit
Dependencies
requestsrequiredInternally used for fetching user agent lists from external websites, but not declared in `setup.py`.
Agent activity
4 hits · last 30 days
node
4
Resources
latest-user-agents — pip install latest-user-agents · libregistry