Python package for visualCaptcha's backend service (compatible with Python 2 and 3)
You need Python installed with pip.
pip install visualcaptcha
Run next command to run unit tests:
python test.py
On initialization visualCaptcha function requires a Session session object as first argument:
from visualcaptcha import Session, Captcha
visualCaptcha = Captcha( Session(session) )
# Optional arguments: visualCaptcha = Captcha( Session(session, namespace), assetsPath, defaultImages, defaultAudios )Where:
sessionis a required shared session object, where correct and option values are stored for later verification in the backendnamespaceis an optional argument. Defaults to'visualcaptcha'and you can use it to use more than one visualCaptcha in the same pageassetsPathis an optional argument. Defaults to the full path of'./assets'.defaultImagesis an optional parameter. Defaults to the array inside of./assets/images.json. Thepathkey is relative to./assets/images/defaultAudiosis an optional parameter. Defaults to the array inside of./assets/audios.json. Thepathkey is relative to./assets/audios/
-
session,Sessionobject — An object that will have a reference for the session object. It will have the following keys insidevisualCaptchakey:images,audios,validImageOption, andvalidAudioOption. -
imageOptions, list — All the image options. These can be easily overwritten withdefaultImageswhen initializingCaptcha. By default, they're populated using the./assets/images.jsonfile. -
audioOptions, list — All the audio options. These can be easily overwritten withdefaultAudioswhen initializingCaptcha. By default, they're populated using the./assets/audios.jsonfile.
generate: ( self, numberOfOptions = 5 )— Generate a new valid visualCaptcha front-end data.numberOfOptions— is an optional parameter for the number of generated images, defaults to5.getFrontendData: ( self )— Get data to be used by the frontend.getValidImageOption: ( self )— Get the current validImageOption.getValidAudioOption: ( self )— Get the current validAudioOption.validateImage: ( self, sentOption )— Validate the sent image value (sentOption) with the validImageOption.validateAudio: ( self, sentOption )— Validate the sent audio value (sentOption) with the validAudioOption.getImageOptions: ( self )— Return generated image options.getImageOptionAtIndex: ( self, index )— Return generated image option at given index.getAudioOption: ( self )— Alias for getValidAudioOption.getAllImageOptions: ( self )— Return all the image options.getAllAudioOptions: ( self )— Return all the audio options.streamAudio: ( self, headers, fileType = 'mp3' )— Stream audio file. Parameters:headersis a list with the HTTP headers to be set;fileTypeis the audio filetype, defaults to'mp3', and it can also be'ogg'.
streamImage: ( self, headers, index, isRetina = False )— Stream image file at given index for generated options. Parameters:headersis a list with the HTTP headers to be set;indexis index of the image in the session images list to receive;isRetina, boolean, deciding if the normal or retina image should be streamed, defaults toFalse.
$ python setup.py sdist upload
View the LICENSE file.