Write Python in your own language, deterministically.
polyglot-python is a keyword transpiler for Python. You keep Python's grammar and write programs with localized keywords; polyglot-python maps those keywords to the real Python keywords and hands the result to CPython. No AI, no network, no randomness: the same source, locale and version always produce byte-identical Python.
It is not a prose-to-code translator and it does not guess intent. It is Python syntax with your words.
pip install polyglot-python
pip install -e . # from sourceRequires Python 3.12+. Python 3.10/3.11 are not supported because their tokenizer splits Indic combining marks, so several Hindi keywords would not translate. No runtime dependencies.
Node.js users can install the thin npm wrapper. It forwards every command to the Python CLI, so the Python package must be installed as well.
npm install -g polyglot-pythonexamples/classify.tr:
fonksiyon classify(n):
eğer n % 15 == 0:
döndür "FizzBuzz"
değilse_eğer n % 3 == 0:
döndür "Fizz"
değilse_eğer n % 5 == 0:
döndür "Buzz"
değilse:
döndür str(n)
için n içinde range(1, 16):
print(classify(n))polyglot-python run examples/classify.tr
polyglot-python check examples/classify.tr
polyglot-python translate examples/classify.tr
polyglot-python translate examples/classify.tr -o classify.pyThe same FizzBuzz program is included for every locale under examples/.
A broader examples/tour.<code> program exercises all 35 keywords — classes,
exceptions, generators, closures, with and async/await — and prints the
same result in every locale:
polyglot-python run examples/tour.tr| Code | Language | if |
def |
return |
|---|---|---|---|---|
| tr | Türkçe | eğer |
fonksiyon |
döndür |
| es | Español | si |
función |
devolver |
| pt | Português | se |
função |
retornar |
| de | Deutsch | wenn |
funktion |
zurückgeben |
| fr | Français | si |
fonction |
retourner |
| zh | 中文 | 如果 |
函数 |
返回 |
| hi | हिन्दी | अगर |
फलन |
लौटाओ |
| ar | العربية | إذا |
دالة |
إرجاع |
| ru | Русский | если |
определить |
вернуть |
| it | Italiano | se |
funzione |
restituisci |
| nl | Nederlands | indien |
functie |
retourneer |
| pl | Polski | jeśli |
funkcja |
zwróć |
| id | Bahasa Indonesia | jika |
fungsi |
kembalikan |
| vi | Tiếng Việt | nếu |
hàm |
trả_về |
| ja | 日本語 | もし |
関数 |
返す |
| ko | 한국어 | 만약 |
함수 |
반환 |
| uk | Українська | якщо |
функція |
повернути |
| ro | Română | dacă |
funcție |
returnează |
| sv | Svenska | om |
funktion |
returnera |
| el | Ελληνικά | αν |
συνάρτηση |
επιστροφή |
polyglot-python locales prints the full list, and polyglot-python keywords tr
prints one locale's complete Python-to-localized mapping. Every locale defines
exactly the 35 Python hard keywords (keyword.kwlist); soft keywords such as
match, case, type and 3.15's lazy stay English.
Locale selection order:
--lang CODE- first line directive:
# polyglot-python: tr - file suffix:
.tr,.es,.pt,.de,.fr,.zh,.hi,.ar,.ru,.it,.nl,.pl,.id,.vi,.ja,.ko,.uk,.ro,.sv,.el
polyglot-python run FILE [--lang CODE] [args...]
polyglot-python check PATH [PATH ...] [--lang CODE]
polyglot-python translate FILE [--lang CODE] [-o OUT]
polyglot-python locales
polyglot-python keywords CODE
polyglot-python --version
For run, place options before FILE; everything after FILE is passed to the
program as sys.argv[1:]. The program executes the way python FILE would:
the script's directory is placed first on sys.path, so sibling modules import
normally, and the program is registered as the __main__ module.
- Only exact
NAMEtokens that match a locale keyword are rewritten. Strings, comments, f-strings, numbers, identifiers and attribute names are untouched. - Line numbers are preserved one-to-one; a per-line column map translates reported error positions back to the localized source.
translate -oand stdout output are UTF-8 with LF line endings on every platform, so exports are byte-identical and re-verifiable.checktranslates and compiles without executing the programs, so localized sources can be validated safely; it accepts several paths and exits nonzero if any of them fails. A directory is searched recursively for files whose suffix names a locale, skipping hidden files and directories.- A localized keyword after a dot is treated as an attribute name and never rewritten.
- Localized keywords are reserved words in their locale.
- Missing files, invalid UTF-8, unknown locales and untokenizable input fail with a clear message; nothing is guessed or silently skipped.
- Error headers are localized; CPython's detail text (for example
ZeroDivisionError) remains English for now. - Exit codes from the executed program are propagated.
runmatches CPython's script behavior: the script's directory leadssys.path(so local imports work) and the program is the__main__module.- That module carries CPython's metadata (
__loader__,__cached__while the interpreter still defines it,__builtins__), and runtime tracebacks show only the program's own frames, never the translator's internals. - A downstream pipe that closes early (
translate FILE | head) exits quietly with status 1 instead of printing a traceback.
- Phase 1 localizes keywords only: no localization of builtins (
print,range, ...), the standard library, or English exception text. - This is not a natural-language compiler. It does not understand Spanish or Turkish prose; it understands Python syntax written with localized keywords.
- The local prototype ships 20 locales. Other languages can be added by editing
src/polyglot_python/locales.json; malformed tables are rejected at load time. - Tested on CPython 3.12 on Windows; CI covers 3.12-3.15 on Linux and 3.12 on Windows and macOS. The code targets 3.12+.
python -m venv .venv
.venv/Scripts/pip install -e ".[dev]"
.venv/Scripts/python -m pytest -q --cov=polyglot_python --cov-fail-under=100The suite contains 242 tests with 100% statement coverage, including every keyword in both directions for all 20 locales, end-to-end CLI runs of every example, version consistency with the changelog and the npm wrapper, and byte-level determinism checks. CI runs Ubuntu 3.12-3.15 plus Windows and macOS at 3.12, enforces the 100% coverage gate on Linux 3.12, translates every example twice on all three operating systems to compare bytes and line counts, builds the wheel, installs it into a clean environment, checks every example with it and runs one end to end, and runs the npm wrapper against the installed Python package. Dependabot keeps GitHub Actions and development dependencies current. Separate release workflows publish tagged GitHub Releases to PyPI and npm through Trusted Publishing.
Publishing uses Trusted Publishing for both registries and stores no API token.
- Configure the trusted publishers once:
- PyPI: publisher for project
polyglot-python: ownerFurox-Art, repositorypolyglot-python, workflowrelease.yml, environmentpypi. - npm: trusted publisher for package
polyglot-python: ownerFurox-Art, repositorypolyglot-python, workflowrelease-npm.yml, environmentnpm.
- PyPI: publisher for project
- Change
versioninpyproject.toml,src/polyglot_python/__init__.pyandnpm/package.jsontogether; the test suite rejects drift. - Publish a GitHub Release with tag
v<version>.release.ymlverifies the tag, builds the sdist and wheel, and uploads them to PyPI;release-npm.ymlverifies the same version and publishesnpm/to npm with provenance.
MIT