python-wsl is a python3 library for working with WSL databases.


Let's parse this example database and run a hierarchical query to make a nice tree.

import wsl
import wsl.wslh as wslh

schema, tables = wsl.parse_db(dbfilepath="world_x.wsl.txt")

specstring = """
Countries: dict for (ctry short desc) (Country ctry short desc)
    _key_: value ctry
    _val_: dict for (cityid cityname district pop) (City cityid cityname ctry district pop)
        _key_: value cityid
        _val_: struct
            name: value cityname
            district: value district
            population: value pop

spec = wslh.parse_spec(schema, specstring)

objects = wslh.rows2objects(schema, spec, tables)
jsontext = wslh.objects2json(schema, spec, objects)



  "Countries": {
    "AFG": {
      "1": {      
        "district": "Kabol",
        "name": "Kabul",
        "population": 1780000
      "2": {      
        "district": "Qandahar",
        "name": "Qandahar",
        "population": 237500

In this case the hierarchical query is not isomorphic. Isomorphic queries work both ways: You can modify the answer tree and convert it back to a WSL database, using just two more lines of code. (There are still some rough edges and it's not yet possible to update subsets of the database).

Download / Installation


The easiest way to get python-wsl is to install it with pip3: just say pip3 install --user wsl. To upgrade to newer available versions, do pip3 install --user --upgrade wsl.

Debian Package

There is also a Debian package which might work on your Debian or Debian-derived distribution. As root, create a file /etc/apt/sources.list.d/python-wsl.list with the following contents:

deb [arch=amd64] wsl-jessie main
deb-src wsl-jessie main

For secure APT you can also add the maintainer's GPG Key, for example by doing wget -O - | apt-key add -. But make sure you understand the implications of adding that key!

You should now by able to do apt-get update followed by apt-get install python3-wsl (notice: python3-wsl).


Github repo


Online documentation.

The documentation can also be built from the project sources. To build you need the python3-sphinx package (under Debian) and the Sphinx autodoc extension, as well as the relatively new `napoleon` extension (which is included in python3-sphinx since Debian stretch). If the dependencies are satisfied, you can type make -C docs/ html from the project root.