https://github.com/rimeinn/pyrime
ㄓ rime for python 🐍️
https://github.com/rimeinn/pyrime
prompt-toolkit ptpython python rime
Last synced: 4 months ago
JSON representation
ㄓ rime for python 🐍️
- Host: GitHub
- URL: https://github.com/rimeinn/pyrime
- Owner: rimeinn
- License: gpl-3.0
- Created: 2024-07-31T16:01:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-08-31T16:15:57.000Z (4 months ago)
- Last Synced: 2025-08-31T16:22:34.488Z (4 months ago)
- Topics: prompt-toolkit, ptpython, python, rime
- Language: Python
- Homepage: https://pyrime.readthedocs.io/
- Size: 246 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- rime-list - rimeinn/pyrime
README
# pyrime
[](https://pyrime.readthedocs.io)
[](https://results.pre-commit.ci/latest/github/rimeinn/pyrime/main)
[](https://github.com/rimeinn/pyrime/actions)
[](https://codecov.io/gh/rimeinn/pyrime)
[](https://github.com/rimeinn/pyrime/releases)
[](https://github.com/rimeinn/pyrime/releases/latest)
[](https://github.com/rimeinn/pyrime/issues)
[](https://github.com/rimeinn/pyrime/issues?q=is%3Aissue+is%3Aclosed)
[](https://github.com/rimeinn/pyrime/pulls)
[](https://github.com/rimeinn/pyrime/pulls?q=is%3Apr+is%3Aclosed)
[](https://github.com/rimeinn/pyrime/discussions)
[](https://github.com/rimeinn/pyrime/milestones)
[](https://github.com/rimeinn/pyrime/network/members)
[](https://github.com/rimeinn/pyrime/stargazers)
[](https://github.com/rimeinn/pyrime/watchers)
[](https://github.com/rimeinn/pyrime/graphs/contributors)
[](https://github.com/rimeinn/pyrime/graphs/commit-activity)
[](https://github.com/rimeinn/pyrime/commits)
[](https://github.com/rimeinn/pyrime/releases/latest)
[](https://github.com/rimeinn/pyrime/blob/main/LICENSE)
[](https://github.com/rimeinn/pyrime)
[](https://github.com/rimeinn/pyrime)
[](https://github.com/rimeinn/pyrime)
[](https://github.com/rimeinn/pyrime)
[](https://github.com/rimeinn/pyrime)
[](https://github.com/rimeinn/pyrime)
[](https://pypi.org/project/pyrime/#description)
[](https://pypi.org/project/pyrime/#history)
[](https://pypi.org/project/pyrime/#files)
[](https://pypi.org/project/pyrime/#files)
[](https://pypi.org/project/pyrime/#files)
[](https://pypi.org/project/pyrime/#files)
[](https://aur.archlinux.org/packages/python-pyrime)
[](https://aur.archlinux.org/packages/python-pyrime)
[](https://aur.archlinux.org/packages/python-pyrime)
[](https://aur.archlinux.org/packages/python-pyrime)
[](https://aur.archlinux.org/packages/python-pyrime)

rime for python, attached to prompt-toolkit keybindings for some prompt-toolkit
applications such as ptpython.
## Dependence
- [librime](https://github.com/rime/librime)
```sh
# Ubuntu
sudo apt-get -y install librime-dev librime1 pkg-config
sudo apt-mark auto librime-dev pkg-config
# ArchLinux
sudo pacman -S --noconfirm librime pkg-config
# Android Termux
apt-get -y install librime pkg-config
# Nix
# use nix-shell to create a virtual environment then build
# homebrew
brew tap tonyfettes/homebrew-rime
brew install librime pkg-config
# Windows msys2
pacboy -S --noconfirm pkg-config librime gcc
```
## Configure
`~/.config/ptpython/config.py`:
```python
from ptpython.repl import PythonRepl
from prompt_toolkit.filters.app import (
emacs_insert_mode,
vi_insert_mode,
vi_navigation_mode,
)
from prompt_toolkit.key_binding.key_processor import KeyPressEvent
from pyrime.ptpython.plugins import RIME
def configure(repl: PythonRepl) -> None:
rime = RIME(repl)
@repl.add_key_binding(
"c-^",
filter=(emacs_insert_mode | vi_insert_mode) & rime.filter(),
)
def _(event: KeyPressEvent) -> None:
rime.toggle()
```
If you defined some key bindings which will disturb rime, try:
```python
@repl.add_key_binding("c-h", filter=emacs_insert_mode & rime.filter())
def _(event: KeyPressEvent) -> None:
rime.toggle()
```
If you want to exit rime in `vi_navigation_mode`, try:
```python
@repl.add_key_binding("escape", filter=emacs_insert_mode)
def _(event: KeyPressEvent) -> None:
""".
:param event:
:type event: KeyPressEvent
:rtype: None
"""
event.app.editing_mode = EditingMode.VI
event.app.vi_state.input_mode = InputMode.NAVIGATION
rime.conditional_disable()
# and a, I, A, ...
@repl.add_key_binding("i", filter=vi_navigation_mode)
def _(event: KeyPressEvent) -> None:
""".
:param event:
:type event: KeyPressEvent
:rtype: None
"""
event.app.editing_mode = EditingMode.EMACS
event.app.vi_state.input_mode = InputMode.INSERT
rime.conditional_enable()
```
It will remember rime status and enable it when reenter `vi_insert_mode` or
`emacs_insert_mode`.
Some utility functions are defined in this project. Refer
[my ptpython config](https://github.com/rimeinn/rimeinn/blob/main/.config/ptpython/config.py)
to know more.