Bootstrap - unihan_db.bootstrap

Fetch, extract, transform, and load UNIHAN into database.

unihan_db.bootstrap.setup_logger(logger=None, level='INFO')
function[source]

Configure logging for CLI use.

Parameters:
  • logger (logging.Logger) – instance of logger

  • level (str) – logging level, e.g. ‘INFO’

Return type:

None

unihan_db.bootstrap.is_bootstrapped(metadata)
function[source]

Return True if cihai is correctly bootstrapped.

Parameters:

metadata (MetaData)

Return type:

bool

unihan_db.bootstrap.bootstrap_data(options=None)
function[source]

Fetch, download, and export UNIHAN data in dictionary format.

Parameters:

options (UntypedUnihanData | None)

Return type:

UntypedNormalizedData | None

unihan_db.bootstrap.bootstrap_unihan(session, options=None)
function[source]

Bootstrap UNIHAN to database.

Parameters:
  • session (Session | ScopedSession[Any])

  • options (UntypedUnihanData | None)

Return type:

None

unihan_db.bootstrap.setup_orm_mappings(mapper, class_)
function[source]

Add special methods to Base declarative model used in Unihan DB.

Parameters:
Return type:

None

unihan_db.bootstrap.to_dict(obj, found=None)
function[source]

Return dictionary of an SQLAlchemy Query result.

Supports recursive relationships.

Parameters:
Returns:

dictionary representation of a SQLAlchemy query

Return type:

dict

unihan_db.bootstrap.add_to_dict(b)
function[source]

Add to_dict() method to SQLAlchemy Base object.

Parameters:

b (declarative_base()) – SQLAlchemy Base class

Return type:

Any

unihan_db.bootstrap.get_session(engine_url='sqlite:///{user_data_dir}/unihan_db.db')
function[source]

Return new SQLAlchemy session object from engine string.

engine_url accepts a string template variable for {user_data_dir}, which is replaced to the XDG data directory for the user running the script process. This variable is only useful for SQLite, where file paths are used for the engine_url.

Parameters:

engine_url (str) – SQLAlchemy engine string

Return type:

ScopedSession[Any]