Skip to main content

Glottolog treedb

Latest PyPI Version License Supported Python Versions Monthly downloads

Build

This tool loads the content of the languoids/tree directory from the Glottolog master repo into a normalized SQLite database.

Each file under in that directory contains the definition of one Glottolog languoid. Loading their content into a relational database allows to perform some advanced consistency checks (example) and in general to execute queries that inspect the languoid tree relations in a compact and performant way (e.g. without repeatedly traversing the directory tree).

See pyglottolog for the more general official Python API to work with the repo without a mandatory initial loading step (also provides programmatic access to the references and a convenient command-line interface).

The database can be exported into a ZIP file containing one CSV file for each database table, or written into a single denormalized CSV file with one row per languoid (via a provided SQL query).

As sqlite is the most widely used database, the database file itself (e.g. treedb.sqlite3) can be queried directly from most programming environments. It can also be examined using graphical interfaces such as DBeaver, or via the sqlite3 cli.

Python users can also use the provided SQLAlchemy models to build queries or additional abstractions programmatically using SQLAlchemy core or the ORM (as more maintainable alternative to hand-written SQL queries).

Quickstart

Install treedb (and dependencies):

$ pip install treedb

Clone the Glottolog master repo :

$ git clone https://github.com/glottolog/glottolog.git

Note: treedb expects to find it under ./glottolog/ by default (i.e. under the current directory), use treedb.set_root() to point it to a different path.

Load ./glottolog/languoids/tree/**/md.ini into an in-memory sqlite3 database. Write the denormalized example query into treedb.query.csv:

$ python -c "import treedb; treedb.load(); treedb.write_csv()"

Usage from Python

Start a Python shell:

$ python

Import the package:

>>> import treedb

Use treedb.iterlanguoids() to iterate over languoids as (<path>, dict) pairs:

>>> next(treedb.iterlanguoids())
(('abin1243',), {'id': 'abin1243', 'parent_id': None, 'level': 'language', ...

Note: This is a low-level interface, which does not require loading.

Load the database into treedb.sqlite3 (and set the default engine):

>>> treedb.load('treedb.sqlite3')
...
<treedb._proxies.SqliteEngineProxy filename='treedb.sqlite3' ...>

Run consistency checks:

>>> treedb.check()
...
True

Export into a ZIP file containing one CSV file per database table:

>>> treedb.csv_zipfile()
...Path('treedb.zip')

Execute the example query and write it into a CSV file with one row per languoid:

>>> treedb.write_csv()
...Path('treedb.query.csv')

Rebuild the database (e.g. after an update):

>>> treedb.load(rebuild=True)
...
<treedb._proxies.SqliteEngineProxy filename='treedb.sqlite3' ...>

Execute a simple query with sqlalchemy core and write it to a CSV file:

>>> import sqlalchemy as sa
>>> treedb.write_csv(sa.select(treedb.Languoid), filename='languoids.csv')
...Path('languoids.csv')

Get one row from the languoid table via sqlalchemy core (in Glottocode order):

>>> next(treedb.iterrows(sa.select(treedb.Languoid)))
('3adt1234', '3Ad-Tekles', 'dialect', 'nort3292', None, None, None, None)

Get one Languoid model instance via sqlalchemy orm (in Glottocode order):

>>> session = treedb.Session()
>>> session.query(treedb.Languoid).first()
<Languoid id='3adt1234' level='dialect' name='3Ad-Tekles'>
>>> session.close()

See also

License

This tool is distributed under the MIT license.

Metadata

Release files for treedb 2.7.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for treedb 2.7.3
File Size Uploaded Provenance Actions
treedb-2.7.3.tar.gz 476.7 kB Without provenance Details for treedb-2.7.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for treedb 2.7.3
File Interpreter ABI Platform Actions
treedb-2.7.3-py3-none-any.whl Python 3 none any Details for treedb-2.7.3-py3-none-any.whl

Total release size: 546.8 kB

Release files / treedb-2.7.3.tar.gz

Download URL treedb-2.7.3.tar.gz
Size 476.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6de3b595b6e620278670ac988c36c0701dd6d75ae9169349f1c757475a64748a
BLAKE2b-256 checksum
How to use checksums
fb8a749e83d8601a9e1dece3465c9cd451cedc98d37a89b8cad33973a8c14c1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / treedb-2.7.3-py3-none-any.whl

Download URL treedb-2.7.3-py3-none-any.whl
Size 70.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af723e4e29b3d64538a7e1d103b069d706665d827de70eb01432bbe8a2f32f66
BLAKE2b-256 checksum
How to use checksums
1e8fc20f21de9552305ee33a46bfd1b0fb1ff67137b56ccbe2e8be1d893c0f71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for treedb 2.7.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.7.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page