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
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 = session.query(Unhn).order_by(
    func.random()
).limit(1).first()

pp = pprint.PrettyPrinter(indent=0)

pp.pprint(random_row.to_dict())

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, flake8, mypy, black, isort, tmuxp, and file watcher helpers (e.g. entr(1)).

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.7.1a0.tar.gz (39.9 kB view details)

Uploaded Source

Built Distribution

unihan_db-0.7.1a0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file unihan_db-0.7.1a0.tar.gz.

File metadata

  • Download URL: unihan_db-0.7.1a0.tar.gz
  • Upload date:
  • Size: 39.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for unihan_db-0.7.1a0.tar.gz
Algorithm Hash digest
SHA256 40e64c1805139ec81482841f36ff38129b9eebe32e91d5327ed836f89173883b
MD5 f82ca5125fb0ffcb23f38e0cf6f4a29e
BLAKE2b-256 9043888d83fb26a4ebcfdd675ceaeac5ac24ff8bd8c183d4df059cfb949d3953

See more details on using hashes here.

File details

Details for the file unihan_db-0.7.1a0-py3-none-any.whl.

File metadata

  • Download URL: unihan_db-0.7.1a0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for unihan_db-0.7.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 31d3df9fd615f75f4aaab1a59e012295d203a039495f5384b9bbe4ed5b08d484
MD5 25cce553916dbaa6559fe6065d056224
BLAKE2b-256 96c367b8171c396f1c6ed8ab4493fca0b304c422e10059593a4d9c6b1b3903e7

See more details on using hashes here.

Supported by

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