is-bot
Python package to detect bots/crawlers/spiders via user-agent string. This is a port of the isbot JavaScript module.
Requirements
- Python >= 3.8
- regex >= 2022.8.17
Installation
pip install is-bot
Usage
Simple usage
from is_bot import Bots
bots = Bots()
ua = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/104.0.5112.79 Safari/537.36'
assert bots.is_bot(ua)
ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
assert not bots.is_bot(ua)
Add/remove parsing rules
from is_bot import Bots
bots = Bots()
# Exclude Chrome-Lighthouse from default bot list
ua = 'Mozilla/5.0 (Linux; Android 7.0; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4695.0 Mobile Safari/537.36 Chrome-Lighthouse'
assert bots.is_bot(ua)
bots.exclude(['chrome-lighthouse'])
assert not bots.is_bot(ua)
# Add some browser to default bot list
ua = 'SomeAwesomeBrowser/10.0 (Linux; Android 7.0)'
assert not bots.is_bot(ua)
bots.extend(['SomeAwesomeBrowser'])
assert bots.is_bot(ua)
Get additional parsing information
from is_bot import Bots
bots = Bots()
ua = 'Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 SearchRobot/1.0'
# view the respective match for bot user agent rule
print(bots.find(ua))
#> Search
# list all patterns that match the user agent string
print(bots.matches(ua))
#> ['(?<! (ya|yandex))search', '(?<! cu)bot']
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
is_bot-0.3.7.tar.gz
(9.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file is_bot-0.3.7.tar.gz.
File metadata
- Download URL: is_bot-0.3.7.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57a83dc85b2d53603a173d7d7e62febfd442f43669792ede8818497ac2d22f7f
|
|
| MD5 |
2b2be9262f4a6f564c6579f201e5ddd0
|
|
| BLAKE2b-256 |
26596d73ad2e8cdcd79a6b928af73dd28e20054dc5be22f55b59efb59cdeaf1a
|
File details
Details for the file is_bot-0.3.7-py3-none-any.whl.
File metadata
- Download URL: is_bot-0.3.7-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9086ed8e03993c21e4c5af5851f92e6c06ca6011195814131a7c4048c23e3a4
|
|
| MD5 |
6d56bd4e62d42d166c262ddd6ca0ffe4
|
|
| BLAKE2b-256 |
11f22155f3b97d01573ed9ededcf44aa23235746a1e0e827c2f444c2b7fef9e5
|