Using WCAG-Zoo in other languages

Below are a small number of example scripts that show how to call the WCAG-Zoo scripts from a number of target languages to provide runtime support for accessibility checking.

All of the following snippets will either:

  • Store a specified string my_html as the temporary file accessed by the variable tmp_file or
  • Pass a specified string my_html into the command via stdin


  1. Execute the WCAG command wcag_zoo.validators.tarsier using Python and store the result as results
  2. Capture the results string and parse it from JSON into the variable json_results
  3. Prints the number of failures for the file

All of the following scripts are public domain samples and not guaranteed to work in production in any way. All scripts should output something similar to /tmp/wcag117015-32930-onps7o 1 failures


File based:

Assuming you have temp installed using npm install temp:

#!/usr/bin/env node
var temp = require('temp'),
    fs   = require('fs'),
    exec = require('child_process').exec;'wcag', function(err, info) {
  if (!err) {
    fs.write(info.fd, "<html><head><body><h2>This is wrong, it should be h1");
    fs.close(info.fd, function(err) {
      exec("zookeeper tarsier '" + info.path + "' -J",
        function(err, stdout) {
          results = stdout;
          json_results = JSON.parse(results);


File based:

#!/usr/bin/env perl
require File::Temp;
use File::Temp ();
use File::Temp qw/ :seekable /;
use JSON;

$my_html = "<html><head><body><h2>This is wrong, it should be h1";

$tmp = File::Temp->new();
print $tmp $my_html;
$tmp->seek( 0, SEEK_END );

$fn = $tmp->filename;

$results = `zookeeper tarsier $fn -J`;
@json_results = decode_json($results);
$filename = @{@{@json_results[0]}[0]}[0];
$len = scalar @{@{@{@{@json_results[0]}[0]}[1]}{'failures'}};
print "$filename $len failures\n";


Included for reference, but WCAG-Zoo can be used in Python by importing validators directly.

File based:

#!/usr/bin/env python2
from __future__ import print_function
import json
import tempfile
import subprocess

my_html = "<html><head><body><h2>This is wrong, it should be h1"

tmp_file = tempfile.NamedTemporaryFile()

process = subprocess.Popen(
    ["zookeeper", "tarsier",, "-J"],

results = process.communicate()[0]
json_results = json.loads(results)



Assuming you have installed json like so: gem install json

File based:

#!/usr/bin/env ruby
require 'json'
require 'tempfile'

my_html = "<html><head><body><h2>This is wrong, it should be h1"

tmp_file ='foo')

results = `zookeeper tarsier #{tmp_file.path} -J`
json_results = JSON.parse(results)
print json_results[0][0], " ", json_results[0][1]['failures'].size, " failures\n"