Extending¶
Extension classes let advanced users add datasets or dataset-specific behavior to
cihai.core.Cihai. Start with cihai.extend.Dataset; use
cihai.extend.DatasetPlugin when the behavior belongs under an existing dataset.
cihai.extend.ConfigMixin and cihai.extend.SQLAlchemyMixin are available when an
extension needs shared configuration or the application database handle.
Cihai Plugin System.
Status: Experimental, API can change
As a pilot, the UNIHAN library, and an plugin for it, in #131.
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¶class cihai.extend.ConfigMixin¶
Bases:
objectCihai 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.
Configuration attributes¶
config.cihaiLinks directly back to Cihai’s configuration dictionary.
configYour local user’s config.
check()Optional function run on start. It can raise dataset config exceptions.
default_configYour dataset’s default configuration.
get_default_configOverride function for custom configs, such as platform-specific database drivers or version checks. Internal functions use
get_default_config().
-
class cihai.extend.SQLAlchemyMixin¶class cihai.extend.SQLAlchemyMixin¶
Bases:
objectCihai 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.
-
class cihai.extend.Dataset¶class cihai.extend.Dataset¶
Bases:
objectCihai dataset, e.g. UNIHAN.
See also
cihai.data.unihan.dataset.Unihanreference implementation
-
class cihai.extend.DatasetPlugin¶class cihai.extend.DatasetPlugin¶
Bases:
objectExtend the functionality of datasets with custom methods, actions, etc.
See also
cihai.data.unihan.dataset.UnihanVariantsreference implementation