lingpy package



lingpy.cache module

Implements the lingpy cache.

Some operations in lingpy may be time consuming, so we provide a mechanism to cache the results of these operations.

lingpy.cache.dump(data, filename)

lingpy.cli module

class lingpy.cli.Command

Bases: object

Base class for subcommands of the lingpy command line interface.

help = None
output(args, content)
classmethod subparser(parser)

Hook to define subcommand arguments.

class lingpy.cli.CommandMeta(name, bases, dct)

Bases: type

A metaclass which keeps track of subclasses, if they have all-lowercase names.

lingpy.cli.add_cognate_identifier_option(p, default)
lingpy.cli.add_format_option(p, default, choices)
lingpy.cli.add_method_option(p, default, choices, spec='')
lingpy.cli.add_mode_option(p, choices)
lingpy.cli.add_option(parser, name_, default_, help_, short_opt=None, **kw)
lingpy.cli.add_strings_option(p, n)
class lingpy.cli.alignments

Bases: lingpy.cli.Command

Carry out alignment analysis of a wordlist file with readily detected cognates.

classmethod subparser(p)

Bases: lingpy.cli.Command

Show help for commands.

classmethod subparser(parser)
class lingpy.cli.lexstat

Bases: lingpy.cli.Command

classmethod subparser(p)

LingPy command line interface.

class lingpy.cli.multiple

Bases: lingpy.cli.Command

Multiple alignment console interface for LingPy.

classmethod subparser(p)
class lingpy.cli.pairwise

Bases: lingpy.cli.Command

Run pairwise analyses from command line in LingPy


Currently, the following options are supported:

  • run normal analyses without sound class strings
  • run sound-class based analyses

Furthermore, input output is handled as follows:

  • define user input using psa-formats in lingpy
  • define user output (stdout, file)
classmethod subparser(p)
class lingpy.cli.profile

Bases: lingpy.cli.Command

classmethod subparser(p)
class lingpy.cli.settings

Bases: lingpy.cli.Command

classmethod subparser(p)
class lingpy.cli.wordlist

Bases: lingpy.cli.Command

Load a wordlist and carry out simple checks.

classmethod subparser(p)

lingpy.compat module

Functionality to provide compatibility across supported python versions

lingpy.config module

Configuration management for lingpy.

Various aspects of lingpy can be configured and customized by the user. This is done with configuration files in the user’s config dir.

class lingpy.config.Config(name, default=None, **kw)

Bases: configparser.RawConfigParser

lingpy.log module

Logging utilities

class lingpy.log.CustomFilter(name='')

Bases: logging.Filter

class lingpy.log.Logging(level=10, logger=None)

Bases: object

A context manager to execute a block of code at a specific logging level.

lingpy.log.debug(msg, **kw)
lingpy.log.deprecated(old, new)
lingpy.log.error(msg, **kw)
lingpy.log.file_written(fname, logger=None)
lingpy.log.get_logger(config_dir=None, force_default_config=False, test=False)

Get a logger configured according to the lingpy log config file.

Note: If no logging configuration file exists, it will be created.

  • config_dir – Directory in which to look for/create the log config file.
  • force_default_config – Configure the logger using the default config.
  • test – Force reconfiguration of the logger.

A logger., **kw)
lingpy.log.missing_module(name, logger=None)

lingpy.settings module

Module handels all global parameters used in a LingPy session.

lingpy.settings.rc(rval=None, **keywords)

Function changes parameters globally set for LingPy sessions.


rval : string (default=None)

Use this keyword to specify a return-value for the rc-function.

schema : {“ipa”, “asjp”}

Change the basic schema for sequence comparison. When switching to “asjp”, this means that sequences will be treated as sequences in ASJP code, otherwise, they will be treated as sequences written in basic IPA.


This function is the standard way to communicate with the rcParams dictionary which is not imported as a default. If you want to see which parameters there are, you can load the rcParams dictonary directly:

>>> from lingpy.settings import rcParams

However, be careful when changing the values. They might produce some unexpected behavior.


Import LingPy:

>>> from lingpy import *

Switch from IPA transcriptions to ASJP transcriptions:

>>> rc(schema="asjp")

You can check which “basic orthography” is currently loaded:

>>> rc(basic_orthography)
>>> rc(schema='ipa')
>>> rc(basic_orthography)

lingpy.util module

class lingpy.util.TemporaryPath(suffix='')

Bases: object

class lingpy.util.TextFile(path, log=True)

Bases: object

lingpy.util.as_string(obj, pprint=False)
lingpy.util.charstring(id_, char='X', cls='-')

Convenience shortcut

lingpy.util.join(sep, *args, **kw)

Convenience shortcut. Strings to be joined do not have to be passed as list or tuple.


An implicit conversion of objects to strings is performed as well.


Convenience shortcut, for the name, see the Wikipedia article on Combination.


Converts a string to a nexus “safe” representation (i.e. removes many unicode characters and removes some punctuation characters).


s : str

A string to convert to a nexus safe format.


s : str

A string containing a nexus safe label.

lingpy.util.read_config_file(path, **kw)

Read lines of a file ignoring commented lines and empty lines.

lingpy.util.read_text_file(path, normalize=None, lines=False)

Read a text file encoded in utf-8.


path : { Path, str }

File-system path of the file.

normalize : { None, “NFC”, “NFC” }

If not None a valid unicode normalization mode must be passed.

lines : bool (default=False)

Flag signalling whether to return a list of lines (without the line-separation character).


file_content : { list, str }

File content as unicode object or list of lines as unicode objects.


The whole file is read into memory.

lingpy.util.setdefaults(d, **kw)

Shortcut for a common idiom, setting multiple default values at once.


d : dict

Dictionary to be updated.

kw : dict

Dictionary with default values.

lingpy.util.write_text_file(path, content, normalize=None, log=True)

Write a text file encoded in utf-8.


path : str

File-system path of the file.

content : str

The text content to be written.

normalize : { None, “NFC”, “NFD” } (default=False)

If not None a valid unicode normalization mode must be passed.

log : bool (default=True)

Indicate whether you want to log the result of the file writing process.

Module contents

LingPy package for quantitative tasks in historical linguistics.

Documentation is available in the docstrings. Online documentation is available at


algorithm — Basic Algorithms for Sequence Comparison align — Specific Algorithms Alignment Analyses basic — Basic Classes for Language Comparison compare — Basic Modules for Language Comparison convert — Functions for Format Conversion data — Data Handling evaluate — Basic Classes and Functions for Algorithm Evaluation read — Basic Functions for Data Input sequence — Basic Functions for Sequence Modeling thirdparty — Temporary Forks of Third-Party-Modules