Skip to content

Getting Started

Requirements

  • Python 3.9 or later
  • A language pack (pip install foreignthon-xx)

Installation

pip install foreignthon

For global CLI access across projects, use pipx:

pipx install foreignthon

Create a project

fpy new myproject --lang <code>
cd myproject

This scaffolds:

myproject/
├── .foreignthon.toml   # project config
├── .gitignore
├── README.md
└── src/
    └── main.<lang>.py  # hello world in your language

The .foreignthon.toml stores your language and any local pack overrides:

[foreignthon]
lang = "es"
# custom_pack = "custom.json"

File naming

ForeignThon detects the language from the file extension:

script.es.py   →  Spanish
script.ta.py   →  Tamil
script.fr.py   →  French

You can also declare the language at the top of the file:

# foreignthon: es

Or override it at runtime:

fpy run script.py --lang es

Run

fpy run src/main.es.py

Compile

fpy compile src/main.es.py
# → src/main.compiled.py
fpy compile src/main.es.py -o dist/
# → dist/main.compiled.py

The compiled file is standard Python. Commit it alongside your source — anyone can run it without ForeignThon installed.


Validate

fpy check src/main.es.py
# ✓ main.es.py looks good.

Checks syntax without running — useful in CI.


Errors

When something goes wrong, ForeignThon shows the error in your language first, then English:

[ES] ErrorDeDivisionCero: Error división por cero
[EN] ZeroDivisionError: division by zero
     File "src/main.es.py", line 8

Tracebacks point to your original source file, not any intermediate.


Variable names

Variable names are completely optional — English names work alongside foreign keywords with no issues. Only keywords and builtins are ever swapped.


Next steps