Extending - cihai.extend#

Cihai Plugin System.

Status: Experimental, API can change

As a pilot, the UNIHAN library, and an plugin for it, in #131 [1]_

You can bring any data layout / backend you like to cihai.

For convenience, you can use cihai’s configuration namespace and SQLAlchemy settings.

You can also create plugins which extend another. So if Unihan doesn’t have a lookup for variant glyphs, this can be added.

class cihai.extend.ConfigMixin[source]#

Bases: object

Cihai configuration context.

This piggybacks cihai’s global config state, as well as your datasets.

Cihai will automatically manage the user’s config, as well as your datasets, neatly in XDG.

Raises:
  • Functions inside, and what you write relating to dataset config should return

  • CihaiDatasetConfigException (CihaiDatasetException)

  • config.cihai = links directly back to Cihai's configuration dictionary

  • (todo note – make this non-mutable property):

:raises config : dict: your local user’s config :raises check() : function, optional: this is ran on start. it can raise DatasetConfigException :raises default_config : your dataset’s default configuration: :raises get_default_config : override function in case you’d like custom configs (for: instance if you want a platform to use a different db driver, or do version checks, etc.) internal functions use get_default_config()

class cihai.extend.SQLAlchemyMixin[source]#

Bases: object

Cihai RDBMS backend functionality using SQLAlchemy.

Your dataset can use any backend you’d like, we provide a backend for you, that automatically piggybacks on cihai’s zero-config, XDG / SQLAchemy configuration. So it’s preconfigured for the user.

In addition, this mixin gives you access to any other of the user’s sqlalchemy sql that use this mixin. So if you want a dataset that utilizes UNIHAN, you can access that easily.

This will provide the following instance-level properties in methods:

When you have access, it’s expected to keep your tables / databases namespaced so they don’t clobber.

sql: Database#
engine: Engine#

sqlalchemy.engine.Engine instance.

metadata: MetaData#

sqlalchemy.schema.MetaData instance.

session: Session#

sqlalchemy.orm.session.Session instance.

base: AutomapBase#

sqlalchemy.ext.automap.AutomapBase instance.

class cihai.extend.Dataset[source]#

Bases: object

Cihai dataset, e.g. UNIHAN.

See also

cihai.data.unihan.dataset.Unihan

reference implementation

bootstrap()[source]#

Bootstrapping (e.g. fetching, extraction, transform, loading) Cihai data.

Return type:

None

add_plugin(_cls, namespace, bootstrap=True)[source]#

Add plugin for Cihai dataset.

Return type:

None

class cihai.extend.DatasetPlugin[source]#

Bases: object

Extend the functionality of datasets with custom methods, actions, etc.

See also

cihai.data.unihan.dataset.UnihanVariants

reference implementation