Skip to main content

Add your description here

Project description

relayout

A pure Python library that detects and fixes text typed in the wrong keyboard layout.

import relayout

relayout.fix("ghbdtn")   # → "привет"
relayout.fix("привет")   # → "ghbdtn"

No clipboard. No hotkeys. No UI. Just a function that takes a string and returns a string.

Installation

pip install relayout

Usage

fix(text) — auto-detect and convert

import relayout

# Typed "привет" but keyboard was in EN layout
relayout.fix("ghbdtn")        # → "привет"

# Typed "hello" but keyboard was in RU layout
relayout.fix("рудди")         # → "hello"

# Neutral text (digits, spaces) is returned unchanged
relayout.fix("hello 123")     # → "hello 123"

detect(text) — identify which layout was used

relayout.detect("ghbdtn")     # → "en"
relayout.detect("привет")     # → "ru"
relayout.detect("123 456")    # → None  (inconclusive)

convert(text, source_id) — convert without auto-detection

# You know the text is in EN, convert to RU
relayout.convert("ghbdtn", "en")   # → "привет"

# You know the text is in RU, convert to EN
relayout.convert("привет", "ru")   # → "ghbdtn"

List available layouts

relayout.list_layouts()   # → ["en_ru"]

Adding a custom layout

You can register any layout at runtime without modifying the library:

from relayout import LayoutMap, register_layout, fix

ua_ru = LayoutMap.from_parallel_strings(
    id="ua_ru",
    layout_ids=("ua", "ru"),
    chars_a="йцукенгшщзїфівапролджєячсмитьбю",
    chars_b="йцукенгшщзхъфывапролджэячсмитьбю",
)
register_layout(ua_ru)

fix("...", layout_id="ua_ru")

Supported layouts

ID Languages
en_ru English ↔ Russian (QWERTY / JCUKEN)

How it works

  1. Detect — counts characters exclusive to each layout side. Majority wins. Ties and neutral text return None.
  2. Convert — applies a character-by-character translation using Python's str.translate().

Each layout is defined as a .toml file with two parallel strings — one per keyboard side. Adding a new language pair requires only adding a new file.

Development

git clone https://github.com/yourusername/relayout
cd relayout
uv sync
uv run pytest

License

AGPL-3.0

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

relayout-0.1.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

relayout-0.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: relayout-0.1.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.5

File hashes

Hashes for relayout-0.1.0.tar.gz
Algorithm Hash digest
SHA256 557303eaf0ddd92026d8c0130ac04ae47f55a85001f351b044f3ae4e0be27b55
MD5 90aee0e70ef9436b04222f3f9b67d204
BLAKE2b-256 6adca764508222546af26ef53c5f7f6df037f621416ac394ab2fc3ffccee68ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: relayout-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.5

File hashes

Hashes for relayout-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 627810a649821ffac51ffc780e56444d284beb741aa2339792a73cf68bcecbe8
MD5 77d4e9dc925edeaabfea6d32064aabbb
BLAKE2b-256 699aa673d237fa65666643ef482795beec30782b93ae2723c872f0b66ccff081

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