Skip to main content

A cross-platform document converter.

Project description

conver — Cross-platform Word Document Converter

conver is a cross-platform Python package that converts Microsoft Word documents
using native system automation:

  • macOS: JXA (JavaScript for Automation)
  • Windows: PowerShell + Word COM automation

The package provides:

  1. A high-level Python API: conver.conver()
  2. A command-line interface: conver
  3. A low-level IPC layer calling platform scripts
    (convert.jxa for macOS, convert.ps1 for Windows)

Conversion is performed via Microsoft Word itself, ensuring maximum compatibility with .docx, .doc, .rtf, .txt, .html, .odt.


Features

  • Cross-platform: macOS and Windows
  • Uses the actual Microsoft Word engine
  • Clean, minimal Python API
  • CLI with direct input/output or format-selection flags
  • Structured error handling via custom exceptions
  • Filename-only outputs automatically placed next to the input file
  • Safe low-level IPC layer between Python and native automation scripts

Installation

Using pip

pip install conver

Recommended for CLI use: pipx

If you primarily use conver as a command-line tool, it is best installed with pipx.
This isolates the package in its own virtual environment and avoids polluting your system Python:

pipx install conver

After installation:

conver --help

will be available globally.


Requirements

  • Python 3.9+
  • Microsoft Word must be installed on the system
  • macOS (JXA) or Windows (PowerShell + Word COM automation)

Python Usage

Basic example

from conver import conver

conver("document.docx", "document.pdf")

Returns:

Path("/absolute/path/document.pdf")

Filename-only output

conver("/Users/me/docs/a.docx", "a.pdf")

Automatically produces:

/Users/me/docs/a.pdf

Error handling example

from conver import conver, UnsupportedFormat

try:
    conver("a.doc", "a.xyz")
except UnsupportedFormat:
    print("This output format is not supported.")

Python API Reference

conver(input_path, output_path, keep_open=False) -> pathlib.Path

High-level document conversion function.

Parameters

  • input_pathstr or pathlib.Path
    Path to the source document.
  • output_pathstr or pathlib.Path
    Target output filename or full path.
  • keep_openbool
    Whether to keep Microsoft Word open after conversion.

Returns

  • pathlib.Path — absolute path of the output file.

Raises

  • InputFileNotFound
  • UnsupportedFormat
  • WordStartError
  • SaveError
  • IPCError
  • PlatformNotSupported

CLI Usage

The CLI supports two modes: direct output path, or format flags.

1. Explicit input/output

conver input.docx output.pdf

2. Format flags (output placed next to input)

conver input.docx --pdf
conver input.docx --rtf
conver input.docx --txt
conver input.docx --html
conver input.docx --docx

If only one input file and no explicit output is given, the selected format determines the extension:

input.docx --pdf   -> input.pdf
input.docx --rtf   -> input.rtf

Output Behavior

When OUTPUT is omitted, the resulting file is written next to the INPUT file. Examples:

    conver a.docx --pdf   -> a.pdf
    conver /path/x.docx   -> /path/x.pdf

When multiple inputs are provided, --output must be a directory.
If the directory does not exist, it will be created automatically.

Default Format

If no format flag is provided and no explicit output path is given, the default output format is PDF:

conver input.docx  # -> input.pdf

CLI Syntax

Usage:
    conver <input> <output>
    conver <input> [--pdf | --docx | --rtf | --txt | --html] [--keep-open]

Examples:
    conver a.docx a.pdf
    conver a.docx --pdf
    conver /path/to/file.doc --html

CLI Arguments

input
One or more input files. Patterns like *.docx are expanded by the shell.

output
Optional.
For single input: output filename.
For multiple inputs: must be a directory.


Multiple Inputs (Batch Mode)

The CLI can process multiple input files at once:

conver *.docx -o outdir
conver file1.docx file2.docx file3.docx -o converted/

Rules:

  • When multiple inputs are provided, --output must point to a directory.
  • If the directory does not exist, it will be created automatically.
  • If no format flag is provided, the default output format is PDF.
  • Format flags (--pdf, --rtf, etc.) cannot be used together with --output FILE.
  • Globbing (*.docx) is expanded by your shell before reaching the CLI.

Output filenames follow the pattern:

input.docx  ->  outdir/input.pdf

Shell Globbing

Patterns like *.docx are expanded by your shell before the conver command is executed.

Examples: conver *.docx -o outdir conver path/*.rtf --pdf

This means the CLI receives the expanded list of files as separate arguments.

Format-Flag Restrictions

Format-selection flags:

--pdf  --docx  --rtf  --txt  --html

work only when OUTPUT is omitted, i.e.:

Allowed:

conver input.docx --pdf
conver input.docx output.pdf

*Invalid:

conver input.docx output.pdf --pdf

Supported Formats

Conversion capabilities depend on Microsoft Word.

Input formats: .docx, .doc, .pdf, .rtf, .odt, .txt, .html

Output formats: .pdf, .docx, .doc, .pdf, .rtf, .odt, .txt, .html


Platform Notes

macOS (JXA)

The script convert.jxa runs through:

osascript -l JavaScript

macOS may require granting Microsoft Word file-access permissions.

Windows (PowerShell)

The script convert.ps1 uses:

Word.Application COM automation

If Word prompts the user, automation must be allowed.


Low-Level Error Codes (Reference)

These codes come from platform scripts and are mapped to exceptions by conver():

Code Meaning
0 Success
1 Invalid JSON from stdin
2 Unsupported input format
3 Unsupported output format
11 Input file not found
21 Word startup timeout
31 Word could not save the file
98 Script produced invalid JSON
99 Unsupported platform

License

MIT License
(c) 2024 Timur Ulyahin
https://github.com/ucomru


Project Homepage

GitHub:
https://github.com/ucomru/python-conver

PyPI:
https://pypi.org/project/conver/

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

conver-0.1.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

conver-0.1.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file conver-0.1.0.tar.gz.

File metadata

  • Download URL: conver-0.1.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for conver-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f730d369b164fde2eb6e050654df3a4951d7d03ed0746e266e4baa458d6fce7c
MD5 a35ab9e526b4fadc8859956f542dd8bf
BLAKE2b-256 3d7d46c8d32e669deeff5c791a44e8c779eb9ec101f5e079342ecebbae58af52

See more details on using hashes here.

File details

Details for the file conver-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: conver-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for conver-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f9dfd300a196436b767f489c3378b4e892b0dc8ad8d2bf986b48f5b6dbbdec8
MD5 c824b885ae7bdd6107ce1b18e44fabe8
BLAKE2b-256 f90d1a250c173a337daab4162f05c7fa7f9a748c7fd1175e878ee18099b53bb9

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 Pingdom Monitoring Sentry Error logging StatusPage Status page