Core - cihai.core#

Cihai core functionality.

exception cihai.core.CihaiConfigError[source]#

Bases: CihaiException

Cihai Configuration error.

cihai.core.is_valid_config(config)[source]#

Upcast cihai configuration.

NOTE: This does not validate configuration yet!

Return type:

TypeGuard[ConfigDict]

class cihai.core.Cihai(config=None, unihan=True)[source]#

Bases: object

Central application object.

By default, this automatically adds the UNIHAN dataset.

config#
Type:

dict

Notes

Inspired by the early pypa/warehouse application object [1]_.

Configuration templates

The config dict parameter supports a basic template system for replacing XDG Base Directory directory variables, tildes and environmentas variables. This is done by passing the option dict through cihai.config.expand_config() during initialization.

Examples

To use cihai programmatically, invoke and install the UNIHAN [2]_ dataset:

Above: is_bootstrapped can check if the system has the database installed.

References

Initialize Cihai application.

Parameters:
  • config (dict, optional) –

  • unihan (boolean, optional) – Bootstrap the core UNIHAN dataset (recommended)

default_config: UntypedDict = {'database': {'url': 'sqlite:///{user_data_dir}/cihai.db'}, 'datasets': {}, 'debug': False, 'dirs': {'cache': PosixPath('/home/runner/.cache/cihai'), 'data': PosixPath('/home/runner/.local/share/cihai'), 'log': PosixPath('/home/runner/.cache/cihai/log')}, 'plugins': {}}#

dict of default config, can be monkey-patched during tests

unihan: Unihan#
config: ConfigDict#
sql: Database#

Database instance

Type:

cihai.db.Database

bootstrap()[source]#

Initialize Cihai.

Return type:

None

add_dataset(_cls, namespace)[source]#

Add dataset to Cihai.

Return type:

None

classmethod from_file(config_path, *args, **kwargs)[source]#

Create a Cihai instance from a JSON or YAML config.

Return type:

Cihai

Parameters:

config_path (str, optional) – path to custom config file

Returns:

application object

Return type:

Cihai