fastuaparser
A super-fast user-agent string parser
Usage
from fastuaparser import parse_ua
# Parse the header info
client_os = parse_ua(headers.get("user-agent", ""))
# Split in browser-type and OS
client, os = client_os.partition(' - ')
The parse_ua() function never raises an exception, just tries
to make as much from whatever you feed it.
A bit less precise, a whole lot faster
This code is less precise than https://github.com/ua-parser/uap-python, in that it marks rare browsers as either "Browser" or as the browser that it's based upon (e.g. IceWeasel becomes Firefox). It also marks all bots as simply "Bot" and does not care about TV's that have a browser. Other than that, this function is quite accurate and passes ua-parser's test suite.
If you can live with the above restrictions (you probably can if you're using this to e.g. monitor your website's traffic) then use this function: it's over 100 times faster that ua_parser!
On the ua-parser's set of ua strings, it renders close to 1M strings per second (in my Mac M1).
Docs
def parse_ua(s: str, always_include_os: bool = False) -> str:
"""Parse the given user-agent string and return a short description.
The returned string has the form "client - os".
The client is "Browser" if unknown. The os is "Other" if unknown
and may contain a string "Mobile", "Tablet" or "Desktop. When the
ua does not represent a browser (but e.g. a bot or wget) the os is
omitted (unless always_include_os is True).
"""
...
Origins
This code used to be part of my time tracking app, which went open source, and I rolled some components (like this one) into their own little project.
License
MIT
Metadata
Release files for fastuaparser 0.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 | |
|---|---|---|---|
| fastuaparser-0.1.4.tar.gz | 8.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastuaparser-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.2 kB
Release files / fastuaparser-0.1.4.tar.gz
| Download URL | fastuaparser-0.1.4.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c0b9113d17e40705dbf4582ca1303c703e2ea03ffdb2f0507afe267a317a3e79
|
|
BLAKE2b-256 checksum How to use checksums |
38c85f8d0f39e5827555598859248fa84f8633493266507ddb902590e6488edf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / fastuaparser-0.1.4-py3-none-any.whl
| Download URL | fastuaparser-0.1.4-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f84be99b435c73849d408b6cd161bdc752881054a7731a810d0deb8fd89842e
|
|
BLAKE2b-256 checksum How to use checksums |
15e039fa18142fd1e9de6e207409dd8e5f90c1cc1346a838ce81a250c3a195fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|