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.6.tar.gz
(14.6 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
is_bot-0.3.6-py3-none-any.whl
(12.8 kB
view details)
File details
Details for the file is_bot-0.3.6.tar.gz.
File metadata
- Download URL: is_bot-0.3.6.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e99d4b71ef916912c82a1ccb61cf0df55e78a4b98c9a69787a2431e664750af8
|
|
| MD5 |
2bb33ba31d1b544289261d9a6f4fc85a
|
|
| BLAKE2b-256 |
d10e06f6810d93aa3b1df934c97b521bd0e0c3ad0b98a2dd39fcdf34587099df
|
File details
Details for the file is_bot-0.3.6-py3-none-any.whl.
File metadata
- Download URL: is_bot-0.3.6-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85cf5eeb7c1d94ba9b9ecb5b2e99ba108a685b7f7131b2a4b9b14badbb0eeb05
|
|
| MD5 |
1e5063dab91afd377d6143ca7b3b0ac2
|
|
| BLAKE2b-256 |
d3ca69c6a56754dc26bea14d1034bcdcb18942142096b0d35d2ff4a7662289bc
|