Skip to main content

Python library for Rich Text Format with Court Reporting Extensions (RTF/CRE) dictionaries

Project description

rtfcre

pypi python tests

rtfcre is a Python library for reading and writing steno dictionaries in the RTF/CRE (Rich Text Format with Court Reporting Extensions) format. The library provides an API similar to that of the json module for reading and writing dictionaries.

rtfcre also comes with a little command-line utility that you can use to convert your dictionaries between Plover's native JSON format and RTF. See CLI for more information.

Features

  • Speed: The parsing logic is written in Rust using parser combinators, making it much faster than practically any pure-Python implementation.

  • Comments: Rather than just exposing translations, rtfcre also reads the comments embedded in each entry ({\*\cxcomment like this}).

  • Unicode: Full Unicode support -- while the dictionary files are not encoded in UTF-8, Unicode characters in translations are still fully supported. Translations can be in any language and they will seamlessly be converted to escapes when writing.

  • Plover support: Translations are converted automatically to Plover's native syntax (e.g. fingerspelling is represented with {&a} rather than {\cxfing a}) and converted back when writing.

Installation

To install the library:

pip install rtfcre

If you just want to use this with Plover, install the plover-better-rtf plugin instead, since that plugin uses this library under the hood.

If you want the command-line utility, go to the Releases page and download the binary for your system.

Usage

Library

To read an RTF dictionary:

import rtfcre

# Reading directly from a file (make sure to open binary)
with open("dict.rtf", "rb") as file:
  dic = rtfcre.load(file)

# Reading from a string
rtf = r"""
{\rtf1\ansi{\*\cxrev100}\cxdict{\*\cxsystem KittyCAT}
{\*\cxs KAT}cat
{\*\cxs KOU}cow
}
""".lstrip()
dic = rtfcre.loads(rtf)

To write the RTF dictionary:

# Writing to a file (make sure to open binary)
with open("dict.rtf", "wb") as file:
  dic.dump(file)

# Writing to a string
rtf = dic.dumps()

The dictionary object itself also supports the standard dict API:

dic["KAT"] = "cat"

"KAT" in dic  # True
dic["KAT"]  # "cat"

del dic["KAT"]

dic["TKOG"]  # KeyError
dic["TKOG"] = "dog"
dic["TKOG"]  # "dog"

as well as a reverse lookup API for mapping from translations to steno strokes:

dic.reverse_lookup("cat")  # ["KAT"]

To access comments:

dic.lookup("TKOG")  # ("dog", None)

dic.add_comment("TKOG", "TK means D")
dic.lookup("TKOG")  # ("dog", "TK means D")

dic.remove_comment("TKOG")

CLI

To convert an existing Plover JSON dictionary to RTF:

rtfcre path/to/input.json path/to/output.rtf

To convert an existing RTF dictionary back to Plover JSON:

rtfcre path/to/input.rtf path/to/output.json

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

rtfcre-2.0.1-cp39-none-win_amd64.whl (571.2 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

rtfcre-2.0.1-cp39-cp39-manylinux_2_24_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

rtfcre-2.0.1-cp39-cp39-macosx_10_7_x86_64.whl (710.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

rtfcre-2.0.1-cp38-none-win_amd64.whl (571.2 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

rtfcre-2.0.1-cp38-cp38-manylinux_2_24_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64

rtfcre-2.0.1-cp38-cp38-macosx_10_7_x86_64.whl (710.7 kB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

rtfcre-2.0.1-cp37-none-win_amd64.whl (571.2 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

rtfcre-2.0.1-cp37-cp37m-manylinux_2_24_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.24+ x86-64

rtfcre-2.0.1-cp37-cp37m-macosx_10_7_x86_64.whl (710.7 kB view hashes)

Uploaded CPython 3.7m macOS 10.7+ x86-64

rtfcre-2.0.1-cp36-none-win_amd64.whl (571.6 kB view hashes)

Uploaded CPython 3.6 Windows x86-64

rtfcre-2.0.1-cp36-cp36m-manylinux_2_24_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.24+ x86-64

rtfcre-2.0.1-cp36-cp36m-macosx_10_7_x86_64.whl (710.8 kB view hashes)

Uploaded CPython 3.6m macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page