Skip to main content

unhwp

High-performance Python library for extracting HWP/HWPX Korean word processor documents to Markdown.

Installation

pip install unhwp

Quick Start

import unhwp

# Simple conversion
markdown = unhwp.to_markdown("document.hwp")
print(markdown)

# Extract plain text
text = unhwp.extract_text("document.hwp")

# Full parsing with images
with unhwp.parse("document.hwp") as result:
    print(result.markdown)
    print(f"Sections: {result.section_count}")
    print(f"Paragraphs: {result.paragraph_count}")

    # Save images
    for img in result.images:
        img.save(f"output/{img.name}")

Handling Failures

UnhwpError.kind says why a call failed, so you can react to the reason instead of matching on message text:

from unhwp import ErrorKind, ParseError

try:
    with unhwp.parse(path) as result:
        print(result.markdown)
except ParseError as err:
    if err.kind in (ErrorKind.OLE_CONTAINER, ErrorKind.ZIP_ARCHIVE):
        print("The file is damaged.")
    elif err.kind in (ErrorKind.UNKNOWN_FORMAT, ErrorKind.UNSUPPORTED_FORMAT):
        print("Not a supported HWP/HWPX document.")
    elif err.kind in (ErrorKind.ENCRYPTED, ErrorKind.DISTRIBUTION_RESTRICTED):
        print("The document cannot be opened without authorization.")
    else:
        # Also the right branch for a reason this build has no name for.
        print(f"Extraction failed ({err.kind}): {err}")

The numbers behind ErrorKind are a stable ABI contract: a new reason takes the next free number and existing ones are never renumbered. Always keep a final else — an unrecognised value arrives as a plain int rather than an ErrorKind, so that a newer native library stays usable. kind is ErrorKind.OTHER for failures raised by the wrapper itself, and never ErrorKind.NONE (which means success).

Features

  • Fast: Native Rust library with zero-copy parsing
  • Complete: Extracts text, tables, images, and document structure
  • Clean Output: Optional cleanup pipeline for polished Markdown
  • Format Support: HWP 5.0, HWPX, and HWP 3.x (legacy)

API Reference

Functions

to_markdown(path) -> str

Convert an HWP/HWPX document to Markdown.

markdown = unhwp.to_markdown("document.hwp")

to_markdown_with_cleanup(path, cleanup_options=None) -> str

Convert with optional cleanup.

markdown = unhwp.to_markdown_with_cleanup(
    "document.hwp",
    cleanup_options=unhwp.CleanupOptions.aggressive()
)

extract_text(path) -> str

Extract plain text content.

text = unhwp.extract_text("document.hwp")

parse(path, render_options=None) -> ParseResult

Parse a document with full access to content and images.

with unhwp.parse("document.hwp") as result:
    print(result.markdown)
    print(result.text)
    for img in result.images:
        print(img.name, len(img.data))

detect_format(path) -> int

Detect the document format.

fmt = unhwp.detect_format("document.hwp")
if fmt == unhwp.FORMAT_HWP5:
    print("HWP 5.0 format")
elif fmt == unhwp.FORMAT_HWPX:
    print("HWPX format")

Classes

RenderOptions

Options for Markdown rendering.

opts = unhwp.RenderOptions(
    include_frontmatter=True,
    image_path_prefix="images/",
    preserve_line_breaks=False,
)

CleanupOptions

Options for output cleanup.

# Presets
opts = unhwp.CleanupOptions.minimal()
opts = unhwp.CleanupOptions.default()
opts = unhwp.CleanupOptions.aggressive()
opts = unhwp.CleanupOptions.disabled()

# Custom
opts = unhwp.CleanupOptions(
    enabled=True,
    preset=1,
    detect_mojibake=True,
)

Constants

  • FORMAT_UNKNOWN - Unknown format
  • FORMAT_HWP5 - HWP 5.0 binary format
  • FORMAT_HWPX - HWPX XML format
  • FORMAT_HWP3 - HWP 3.x legacy format

Platform Support

  • Windows (x64)
  • Linux (x64)
  • macOS (x64, ARM64)

License

MIT License - see LICENSE for details.

Links

Download files

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

Source Distribution

unhwp-0.8.0.tar.gz (7.8 MB view details)

Uploaded Source

Built Distribution

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

unhwp-0.8.0-py3-none-any.whl (7.8 MB view details)

Uploaded Python 3

File details

Details for the file unhwp-0.8.0.tar.gz.

File metadata

  • Download URL: unhwp-0.8.0.tar.gz
  • Upload date:
  • Size: 7.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for unhwp-0.8.0.tar.gz
Algorithm Hash digest
SHA256 26b4244a2b53d1c1bc760692c1ae766aecf577d08c244d08f06b30f870b9fb8f
MD5 367c97aca5017247acd37e5a5a4f6efb
BLAKE2b-256 add6e041eb4cb9bf785848b06444505a0988b375a4f0a2f5b6127f65c2a7ca3b

See more details on using hashes here.

File details

Details for the file unhwp-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: unhwp-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for unhwp-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ba2e2029c4167d0343c5df184fe5d3de667d5fb7f5e86f8c70f42c8d7f47df8
MD5 e62a280456bdcb111a1b88c35d6272de
BLAKE2b-256 89f8c35908444e1b10576937de9b7967dc9b884d8a554b677498a8bae23967d5

See more details on using hashes here.

Supported by

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