Python 3 client library for the Google Safe Browsing API (v3)
The original code this project is based on can be found here in afilipovich's repo. It was changed to support Python 3 (exclusively) and stuff like Unit Tests was added and a few more features introduced (like the ability to get the metadata for a match in the Google Safe Browsing List) The master branch is used for development, use a release if you want stability.
While the code was developed according to official Developers Guide this is not a reference implementation and is not affiliated with google in any way. You also may want to check the Acceptable Use Policy for Safe Browsing API. Use this software at your own risk!
This is not an implementation for the Google Safe Browsing Lookup API. The lookup API would be using HTTP requests for each lookup you perform. The implementation used here instead, downloads an offline copy of a part of the database, which allows you to exceed the rate limit of the lookup API. Because of that you have to synchronise the database on the first run though.
Instructions can be found here
Just run:
pip install gglsbl3
And you should be all set!
Download the library, locate setup.py and run
python setup.py install
from gglsbl3 import SafeBrowsingList
sbl = SafeBrowsingList('GOOGLE SAFE BROWSING V3 API KEY HERE')
sbl.update_hash_prefix_cache()
On a first run it may take up to several hours to complete the sync, you may also have to run it several times to fully sync the database. Before you can look up any urls, you have to sync the database.
from gglsbl3 import SafeBrowsingList
sbl = SafeBrowsingList('API KEY GOES HERE')
lookup_result = sbl.lookup_url('http://github.com/')
This will return a list of matched Safe Browsing lists, e.g.
>>> print(lookup_result)
['goog-malware-shavar']
scripts/gglsbl_client.py
can be used for quick testing and as a code example. When installing with pip
or setup.py install
this tools should automatically be in your PATH
.
To sync local cache with Safe Browsing API
gglsbl_client.py --api-key 'API KEY GOES HERE'
The same, but omitting Acceptable Use Policy delays (which is not recommended!)
gglsbl_client.py --api-key 'API KEY GOES HERE' --onetime
To look up a URL
gglsbl_client.py --api-key 'API KEY GOES HERE' --check-url http://github.com/
Fore more options please see
gglsbl_client.py --help
If you have any more questions, feel free to open an issue or email me.