Getting started


clld works with python >=3.5. It has been installed and run successfully on Ubuntu (14.04, 16.04, 18.04), Mac OSX/scripts and Windows. While it might be possible to use sqlite as database backend, all production installations of clld and most development is done with postgresql (9.x or 10.x). To retrieve the clld software from GitHub, git must be installed on the system.


To install the python package from pypi run

$ pip install clld[dev]

To install from a git repository (if you want to hack on clld), you may run the following commands in an activated virtualenv:

$ git clone
$ cd clld
$ pip install -r requirements.txt

Alternatively, you may want to fork clld first and then work with your fork.

Bootstrapping a clld app

A clld app is a python package implementing a pyramid web application.

Installing the clld package will also install a command clld, which offers functionality to kickstart a clld app project. Note that this functionality requires the cookiecutter package to be installed:

$ pip install cookiecutter
$ clld create myapp

This will create a myapp project directroy, containing a python package myapp with the following layout:

(clld)robert@astroman:~/venvs/clld$ tree myapp/
myapp/                           # project directory
├── development.ini              # deployment settings
├── myapp                        # package directory
│   ├──              # custom adapters
│   ├── appconf.ini              # custom application settings
│   ├──                # registers custom static assets with the clld framework
│   ├──            # custom datatables
│   ├──              # contains the main function
│   ├──            # custom interface specifications
│   ├── locale                   # locale directory, may be used for custom translations
│   │   └── myapp.pot
│   ├──                  # custom map objects
│   ├──                # custom database objects
│   ├── scripts
│   │   ├──      # database initialization code
│   │   └──
│   ├── static                   # custom static assets
│   │   ├── project.css
│   │   └── project.js
│   ├── templates                # custom mako templates
│   │   ├── dataset              # custom templates for resources of type Dataset
│   │   │   └── detail_html.mako # the home page of the app
│   │   └── myapp.mako           # custom site template
│   ├── tests
│   │   ├──
│   │   ├──
│   │   └──
│   └──
├── README.txt
├── setup.cfg


$ cd myapp
$ pip install -e .

will install your app as Python package in development mode, i.e. will create a link to your app’s code in the site-packages directory.

Now edit the configuration file, myapp/development.ini providing a setting sqlalchemy.url in the [app:main] section. The SQLAlchemy engine URL given in this setting must point to an existing (but empty) database if the postgresql dialect is chosen.


$ clld initdb development.ini

will then create the database for your app. Whenever you edit the database initialization script, you have to re-run the above command.

You are now ready to run

$ pserve --reload development.ini

and navigate with your browser to to visit your application.

The next step is populating the database.

Populating the database

The clld framework does not provide any GUI or web interface for populating the database. Instead, this is assumed to be done with code in myapp/scripts/ which is run via

$ clld initdb development.ini

Adding objects to the database is done by instantiating model objects and adding them to clld.db.meta.DBSession. (This session is already initialized when your code in runs.) For more information about database objects read the chapter Declarative base and mixins.

A minimal example (building upon the default main function in as created for the app skeleton) adding just two Value objects may look as follows

def main(args):
    data = Data()

    dataset = common.Dataset(id=myapp.__name__, domain='')

    # All ValueSets must be related to a contribution:
    contrib = common.Contribution(id='contrib', name='the contribution')

    # All ValueSets must be related to a Language:
    lang = common.Language(id='lang', name='A Language', latitude=20, longitude=20)

    param = common.Parameter(id='param', name='Feature 1')

    # ValueSets group Values related to the same Language, Contribution and
    # Parameter
    vs = common.ValueSet(id='vs', language=lang, parameter=param, contribution=contrib)

    # Values store the actual "measurements":
    DBSession.add(common.Value(id='v1', name='value 1', valueset=vs))
    DBSession.add(common.Value(id='v2', name='value 2', valueset=vs))

A more involved example, creating instances of all core model classes, is available in chapter Populating the database of a clld app.

The data object present in the main function in is an instance of

class clld.cliutil.Data(**kw)[source]

Dictionary, serving to store references to new db objects during data imports.

The values are dictionaries, keyed by the name of the model class used to create the new objects.

>>> data = Data()
>>> l = data.add(common.Language, 'l', id='abc', name='Abc Language')
>>> assert l == data['Language']['l']
add(model_, key_, **kw)[source]

Create an instance of a model class to be persisted in the database.

  • model – The model class we want to create an instance of.
  • key – A key which can be used to retrieve the instance later.
  • kw – Keyword parameters passed to model class for initialisation.

The newly created instance of model class.

Thus, you can create objects which you can reference later like

data.add(common.Language, 'mylangid', id='1', name='French')
data.add(common.Unit, 'myunitid', id='1', language=data['Language']['mylangid'])


Using data.add for all objects may not be a good idea for big datasets, because keeping references to all objects prevents garbage collection and will blow up the memory used for the import process. Some experimentation may be required if you hit this problem. As a general rule: only use data.add for objects that you actually need to lookup lateron.


All model classes derived from clld.db.meta.Base have an integer primary key pk. This primary key is defined in such a way (at least for PostgreSQL and SQLite) that you do not have to specify it when instantiating an object (although you may do so).

The dataset

Each clld app is assumed to serve a dataset, so you must add an instance of clld.db.models.common.Dataset to your database. This dataset is assumed to have a publisher and a license. Information about the publisher and the license should be part of the data, as well as other metadata about the dataset.

A note on files

A clld app may have static data files associated with its resources (e.g. soundfiles). The clld framework is designed to store these files in the filesystem and just keep references to them in the database. While this does require a more complex import and export process, it helps keeping the database small, and allows serving the static files directly from a webserver instead of having to go through the web application (which is still possible, though).

To specify where in the filesystem these static files are stored, a configuration setting clld.files must point to a directory on the local filesystem. This setting is evaluated when a file’s “create” method is called, or its URL is calculated.

Note that there’s an additional category of static files - downloads - which are treated differently because they are not considered primary but derived data which can be recreated at any time. To separate these concerns physically, downloads are typically stored in a different directory than primary data files.


TODO: clld.environment == ‘production’, webassets need to be built. gunicorn + nginx


A good way explore how to customize a clld app is by looking at the code of existing apps. These apps are listed at and each app links to its source code repository on GitHub (in the site footer).