For AI agents: the complete documentation index is available at https://canary.gukhanmun.org/llms.txt, the full documentation bundle is available at https://canary.gukhanmun.org/llms-full.txt, and this page is available as Markdown at https://canary.gukhanmun.org/guide/python/start.md.

Python quick start

Install Gukhanmun before running these examples. Converter(...) creates a reusable converter backed by Rust. Configure it once, then pass each document to convert().

Convert a document

from gukhanmun import Converter, DictionaryEntry, InputFormat, MapDictionarySource

converter = Converter(dictionaries=[
    MapDictionarySource(entries=[DictionaryEntry(hanja="漢字", reading="한자")]),
])

assert converter.convert("漢字를 한글로") == "한자를 한글로"
assert converter.convert("<p>漢字</p>", format=InputFormat.HTML) == "<p>한자</p>"

Plain text is the default format. Use InputFormat.MARKDOWN for CommonMark, or MarkdownOptions(gfm=True) for GitHub Flavored Markdown:

from gukhanmun import MarkdownOptions

result = converter.convert("# 漢字", format=MarkdownOptions(gfm=True))

Options take enum members, not strings. If a value arrives as a string, convert it first, for example Preset("ko-kr"). Passing preset="ko-kr" directly to Converter() raises TypeError.

Presets do not load official dictionaries. With no explicit sources, conversion uses the built-in character fallback. Supply runtime entries or compiled FST/CDB data when word readings are needed, or install and add the official dictionaries.

Reuse a converter

Dictionary resources are loaded during construction, so configure one converter and reuse it across documents. Its settings are immutable: inspect the resolved configuration through converter.options, and create a new converter to change it. A converter can be shared across threads, as shown in Parallel documents.

Choose the next task

TaskGuide
Add official, in-memory or compiled dictionariesDictionaries
Set presets, numbers and annotation windowsConversion options
Compare parentheses, ruby and original textRendering modes
Force or suppress annotations for a termDirectives
Preserve HTML subtrees or handle malformed inputHTML processing
Convert Markdown and GFMMarkdown conversion
Feed chunks or convert documents in parallelStreaming API

Handle errors

The API reference explains GukhanmunError, its ErrorCode, and the root-first chain of causes. Wrong argument types raise TypeError; lone Unicode surrogates in input raise UnicodeEncodeError.