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.
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 throughcihai.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
- config: ConfigDict¶