While the tools offered by Alphabet are easily accessible on the web, most of the time they remain isolated from existing workflows. With the API, it is possible to access all the information from the Alphabet Database and put it to use in scripts, font editor plugins and websites. The following code snippets and sample scripts explain the basic functionality and how to get started building and enhancing custom tools.
To interact with the Alphabet Database you send requests and receive responses from a server. In Python, this can be easily done with the requests package. If this is not installed on the system already, it can be obtained with the widely used package manager pip and a simmple command.
pip install requests
The most basic HTTP request method is GET. The following script uses this method to retrieve a list of all available character sets included in the database and prints the response.
If everything works as expected, the printed response from the JSON method will return a list of dictionaries. Each dictionary represents a character set, the URL field will lead to details about a particular character set.
The result of the request can also be obtained through the browsable API documentation using the URL: /en/tools/api/v1.0/charactersetdata/characterset/
POST request and data
Another helpful method is the POST request. The tools section of the API allows you to send information to the database and compare it with the data there. In the following example we check a list of Unicode codepoints (basic ASCII in this case) against the language system definition for English.
The returned output will get printed as follows, sorting the codepoints into commonly used categories required, auxiliary and punctuation and listing them in the appropriate dictionaries as missing or present.
POST request and font files
Similar to the previous example, it is also possible to check an existing binary font against the database with the API. This command will only check for encoded characters stored in the cmap table of a font, any other information will not be read or stored.
The printed output will be formatted as follows: