Tired of being forced into deprecated, ancient reCAPTCHA libraries that are devoid of Pythonic beauty?
Want to make your life with reCAPTCHA easier?
Worry no more, Admire is here.
Installing Admire couldn't be simpler. Assuming you have Python and pip installed, just open up your terminal or command prompt and type pip install admire
. Heck, you can even copy and paste it.
Just toss in your expected source and your reCAPTCHA API key. After that, you're good to go:
from admire import Captcha
captcha = Captcha('www.example.org', 'SECRET_API_KEY')
Or, if you're a fan of keyword arguments:
from admire import Captcha
captcha = Captcha(source='www.example.org', secret='SECRET_API_KEY')
But what about if you're expecting a package source instead of a hostname? No problem:
from admire import Captcha
captcha = Captcha('org.example.app', 'SECRET_API_KEY', is_package=True)
Verifying a user-submitted reCAPTCHA token is as easy as:
from admire import Captcha
captcha = Captcha('www.example.org', 'SECRET_API_KEY')
token = captcha.verify_token('TOKEN')
if token:
print('Verified token: {}'.format(token))
else:
print('Could not verify token.')
Admire even supports expirations for challenges! If a reCAPTCHA challenge was requested more than expiration
seconds ago, it will return as if the token is invalid:
from admire import Captcha
captcha = Captcha('www.example.org', 'SECRET_API_KEY')
token = captcha.verify_token('TOKEN', expiration=60)
if token:
print('Verified token: {}'.format(token))
else:
print('Could not verify token or challenge expired.')
If you happen to have the user's IP address, you can use that too for an additional security check:
from admire import Captcha
captcha = Captcha('www.example.org', 'SECRET_API_KEY')
token = captcha.verify_token('TOKEN', remote_ip='127.0.0.1')
if token:
print('Verified token: {}'.format(token))
else:
print('Could not verify token.')
Working with reCAPTCHA doesn't have to be hard and you don't have to suffer.
So, go ahead and grab a drink; you've earned it. 🍻