unihan-db ·

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
Metadata
Release files for unihan-db 0.22.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| unihan_db-0.22.0.tar.gz | 256.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| unihan_db-0.22.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 268.2 kB
Release files / unihan_db-0.22.0.tar.gz
| Download URL | unihan_db-0.22.0.tar.gz |
|---|---|
| Size | 256.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
83edfbac1e4a00447273ef9a078aca430452e9c87d186d9d370428dbfc81332a
|
|
BLAKE2b-256 checksum How to use checksums |
30772fa22d2e253ec3198dc980545eb2d502d0197f12bda9f853253bc4e71ce7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.
Transparency logRelease files / unihan_db-0.22.0-py3-none-any.whl
| Download URL | unihan_db-0.22.0-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f2d7cc83ec181c6548b02f2c4bdcb2d5c6acae575450b5fa2be3c87707be4386
|
|
BLAKE2b-256 checksum How to use checksums |
54a82eaa8ebdbe8703f6fe9126286a4da9ab154ffc1a8e6b45f51cb361ed340a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.
Transparency logSecurity for unihan-db 0.22.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for unihan_db-0.22.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.