Skip to main content

Parsethon 🐍🗣️

Parsethon is an extensible Python lexical parser, tokenization engine, and language translation system. Rather than creating a new programming language implementation, parsethon is a mechanism for expressing Python in multiple syntactic vocabularies while retaining Python's ecosystem and runtime.

It enables developers to:

  1. Tokenize Python source code with fine-grained lexical classification and subelement taxonomy (keywords, operators, delimiters, literals, trivia, and spans).
  2. Define a "Tongue": A declarative mapping of replacement keywords, operators, literals, and built-ins.
  3. Semantically Correct Bidirectional Translation: Convert source code written in a Tongue back to standard canonical Python syntax (and vice-versa) with demonstrably safe, reversible transformations and AST equivalence.
  4. Execute under CPython: Run Tongue source files directly with standard CPython runtime semantics and mapped tracebacks via explicit bidirectional source maps.
  5. Import Seamlessly: Import .tongue.py modules directly via Python's sys.meta_path loader or codec hook (# coding: parsethon-<tongue>).

Built with zero third-party dependencies beyond the in-house CLI interface library expose-interface.


Installation

Using uv:

uv add parsethon

Using pip:

pip install parsethon

Quickstart

1. Command Line Interface (powered by expose-interface)

Parsethon exports a unified CLI tool:

List available Tongues

parsethon list-tongues

Output:

Available Tongues:
  * emoji      (v1.0.0): Iconic Emoji Python Tongue [def->🔨, return->📦, if->❓...]
  * es         (v1.0.0): Spanish language Python Tongue [def->definir, return->retornar, if->si...]
  * js         (v1.0.0): JavaScript-style Python Tongue with braces, semicolons, and JS vocabulary
  * pirate     (v1.0.0): Swashbuckling Pirate Python Tongue [def->chart, return->booty, if->perchance...]

Run a Tongue file

parsethon run examples/fibonacci.es.py

Translate Tongue code to Python

parsethon translate examples/fibonacci.es.py --output fibonacci.py

Inspect Token Breakdown

parsethon tokenize examples/counter.emoji.py

Validate Syntax

parsethon check examples/fibonacci.es.py

2. Python API

Tokenizing Code with Subelement Taxonomy

from parsethon import ParsethonTokenizer

code = "def add(x: int, y: int) -> int:\n    return x + y\n"
tokenizer = ParsethonTokenizer(code)
tokens = tokenizer.tokenize()

for token in tokens:
    if token.category.value not in ("whitespace", "newline"):
        print(f"{token.span}: {token.category.value} ({token.subelement.value}) -> {token.value}")

Defining a Custom Tongue

from parsethon import Tongue, registry

# Create a Latin Tongue
latin = Tongue(
    name="la",
    version="1.0.0",
    description="Latin Python Tongue",
    keywords={
        "def": "definire",
        "return": "reddere",
        "if": "si",
        "else": "aliter",
        "while": "dum",
        "for": "pro",
        "in": "in",
    },
    constants={
        "True": "Verum",
        "False": "Falsum",
        "None": "Nihil",
    },
    builtins={
        "print": "scribere",
    },
)

# Register it
registry.register(latin)

Translating Between Tongue and Python

from parsethon import translate_to_python, translate_from_python

latin_code = """
definire addere(a, b):
    si a > 0:
        reddere a + b
    aliter:
        reddere b
"""

py_code = translate_to_python(latin_code, "la")
print(py_code)
# Output:
# def addere(a, b):
#     if a > 0:
#         return a + b
#     else:
#         return b

Direct CPython Execution

from parsethon import execute

scope = execute(latin_code, tongue="la")
# Functions and variables are ready in scope!

Seamless Module Imports

import parsethon

# Enable Tongue import hooks
parsethon.enable()

# Directly import foo.es.py or foo.emoji.py!
import my_spanish_module
my_spanish_module.saludar("Mundo")

JavaScript-Style Syntax (Braces & Semicolons)

Parsethon supports full JavaScript-style block syntax, semicolons, and complete whitespace indifference:

// calculator.js
function factorial(n) {
    if (n <= 1) {
        return 1;
    } else {
        return n * factorial(n - 1);
    }
}

let result = factorial(5);
console.log("Factorial:", result);

You can execute .js scripts directly:

parsethon run calculator.js

Or import them transparently as Python modules:

import parsethon
parsethon.enable()

import calculator
print(calculator.factorial(5))  # 120

Architecture & Documentation


License

MIT

Metadata

Release files for parsethon 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parsethon 0.3.0
File Size Uploaded Provenance Actions
parsethon-0.3.0.tar.gz 26.6 kB With provenance Details for parsethon-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for parsethon 0.3.0
File Interpreter ABI Platform Actions
parsethon-0.3.0-py3-none-any.whl Python 3 none any Details for parsethon-0.3.0-py3-none-any.whl

Total release size: 57.1 kB

Release files / parsethon-0.3.0.tar.gz

Download URL parsethon-0.3.0.tar.gz
Size 26.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6260296a165f3efe0b64e3a69e013519261828bb3b7c3f12ab09ef48c794aad3
BLAKE2b-256 checksum
How to use checksums
f87acd93bad3dcf286e24adc1e5902e8b819aae70a108c37062981f542ffc4e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / parsethon-0.3.0-py3-none-any.whl

Download URL parsethon-0.3.0-py3-none-any.whl
Size 30.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad8870b1316d177c65542962a90230810daf05c5260404274dcb98d4af7bccad
BLAKE2b-256 checksum
How to use checksums
c62741aea4967239a891e813215ae64876428fbbadf9d2bb660627ae96488bc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for parsethon 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for parsethon-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page