SQLAlchemy models for UNIHAN database
Project description
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
# -*- coding: utf8 - *-
from __future__ import unicode_literals
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
poetry is a required package to develop.
git clone https://github.com/cihai/unihan-etl.git
cd unihan-etl
poetry install -E "docs test coverage lint format"
Makefile commands prefixed with watch_ will watch files and rerun.
Tests
poetry run py.test
Helpers: make test Rerun tests on file change: make watch_test (requires entr(1))
Documentation
Default preview server: http://localhost:8041
cd docs/ and make html to build. make serve to start http server.
Helpers: make build_docs, make serve_docs
Rebuild docs on file change: make watch_docs (requires entr(1))
Rebuild docs and run server via one terminal: make dev_docs (requires above, and a make(1) with -J support, e.g. GNU Make)
Formatting / Linting
The project uses black and isort (one after the other) and runs flake8 via CI. See the configuration in pyproject.toml and setup.cfg:
make black isort: Run black first, then isort to handle import nuances make flake8, to watch (requires entr(1)): make watch_flake8
Releasing
As of 0.11, poetry handles virtualenv creation, package requirements, versioning, building, and publishing. Therefore there is no setup.py or requirements files.
Update __version__ in __about__.py and pyproject.toml:
git commit -m 'build(unihan-db): Tag v0.1.1' git tag v0.1.1 git push git push --tags poetry build poetry deploy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file unihan_db-0.1.0.tar.gz
.
File metadata
- Download URL: unihan_db-0.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.7.7 Linux/4.19.121-microsoft-standard
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0873d95c5d7f6d84e3eda60dca2df2500c923f481ea595a35a3e5f9798814bb |
|
MD5 | 261446748ff01d67b190e54408d385b8 |
|
BLAKE2b-256 | 6e2913641ae8bf5ee45ae1756449b76e46615113b4aa0c2dd642564d29cbd737 |
File details
Details for the file unihan_db-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: unihan_db-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.7.7 Linux/4.19.121-microsoft-standard
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c95ce355e9b04a72defe0b2b1d8e1c40ec361c4d300697a4c0b239ed8f397fce |
|
MD5 | 602088ad565132020016ebbe08cbf19e |
|
BLAKE2b-256 | 29325c413a02233f484af7a6a913ada7c757e965b0e6f0e402f2799588f331a0 |