Skip to main content

SQLAlchemy models for UNIHAN CJK database

Project description

unihan-db · Python Package License Code Coverage

Database SQLAlchemy models for UNIHAN. Part of the cihai project. Powered by unihan-etl. See also: libUnihan.

By default, unihan-db creates a SQLite database in an XDG data directory. You can specify a custom database destination by passing a database url into get_session.

Example usage

#!/usr/bin/env python
"""Example for bootstrapping UNIHAN DB and print out a row."""
import pprint

from sqlalchemy.sql.expression import func

from unihan_db import bootstrap
from unihan_db.tables import Unhn

session = bootstrap.get_session()

bootstrap.bootstrap_unihan(session)

random_row_query = session.query(Unhn).order_by(func.random()).limit(1)

assert random_row_query is not None

random_row = random_row_query.first()

pprint.pprint(bootstrap.to_dict(random_row))

pprint.pprint(random_row.to_dict())  # type:ignore

Run:

$ ./examples/01_bootstrap.py

Output:

{'char': '鎷',
'kCantonese': [{'char_id': '鎷', 'definition': 'maa5', 'id': 24035}],
'kDefinition': [],
'kHanYu': [{'char_id': '鎷',
          'id': 24014,
          'locations': [{'character': 5,
                       'generic_indice_id': 24014,
                       'generic_reading_id': None,
                       'id': 42170,
                       'page': 4237,
                       'virtual': 0,
                       'volume': 6}],
          'type': 'kHanYu'}],
'kHanyuPinyin': [{'char_id': '鎷',
                'id': 18090,
                'locations': [{'character': 5,
                             'generic_indice_id': None,
                             'generic_reading_id': 18090,
                             'id': 42169,
                             'page': 4237,
                             'virtual': 0,
                             'volume': 6}],
                'readings': [{'generic_reading_id': 18090,
                            'id': 26695,
                            'reading': 'mǎ'}],
                'type': 'kHanyuPinyin'}],
'kMandarin': [{'char_id': '鎷', 'hans': 'mǎ', 'hant': 'mǎ', 'id': 23486}],
'ucn': 'U+93B7'}

Developing

$ git clone https://github.com/cihai/unihan-etl.git
$ cd unihan-etl

Bootstrap your environment and learn more about contributing. We use the same conventions / tools across all cihai projects: pytest, sphinx, mypy, ruff, tmuxp, and file watcher helpers (e.g. entr(1)).

Python versions

  • 0.8.0:
    • Last Python 3.7 release
    • Last SQLAlchemy 1.3 release

More information

Docs Build Status

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unihan_db-0.20.1.tar.gz (249.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unihan_db-0.20.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file unihan_db-0.20.1.tar.gz.

File metadata

  • Download URL: unihan_db-0.20.1.tar.gz
  • Upload date:
  • Size: 249.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unihan_db-0.20.1.tar.gz
Algorithm Hash digest
SHA256 9488cfe423c66b4d2810c6f7c308f9c056f558cb50f01c6de64316ccd872a2d3
MD5 ef71450fc9b857eaa07cd3cd321111de
BLAKE2b-256 076480313c129782f0ea27fc02f7d0ecdaa75768253faed906a3d1f32cb6e582

See more details on using hashes here.

Provenance

The following attestation bundles were made for unihan_db-0.20.1.tar.gz:

Publisher: tests.yml on cihai/unihan-db

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file unihan_db-0.20.1-py3-none-any.whl.

File metadata

  • Download URL: unihan_db-0.20.1-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unihan_db-0.20.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0746e389b9d0a3c3559167d574824bd98c73411d867435b7964d079f132ae935
MD5 f0f80fc4052439c2efd0d4788be2cc0f
BLAKE2b-256 6566e5ee1c1f6472fff03dcc5f73f834c239a45506f937d21f979c646161a035

See more details on using hashes here.

Provenance

The following attestation bundles were made for unihan_db-0.20.1-py3-none-any.whl:

Publisher: tests.yml on cihai/unihan-db

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page