{"library":"rply","title":"RPly: Python Lex/Yacc Parser Generator","description":"RPly is a pure Python parser generator, offering a modern API and compatibility with RPython. It is a re-implementation of David Beazley's PLY library. RPly simplifies the process of building lexers (tokenizers) and parsers (syntax analyzers) for domain-specific languages or custom syntaxes. The current version is 0.7.8, and it has a relatively slow release cadence.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install rply"],"cli":null},"imports":["from rply import LexerGenerator","from rply import ParserGenerator","from rply.token import BaseBox","from rply.lexer import LexingError","from rply import ParsingError"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from rply import LexerGenerator, ParserGenerator, ParsingError\nfrom rply.token import BaseBox\n\n# 1. Define the Abstract Syntax Tree (AST) nodes\nclass Number(BaseBox):\n    def __init__(self, value):\n        self.value = value\n\n    def eval(self):\n        return self.value\n\nclass BinaryOp(BaseBox):\n    def __init__(self, left, right):\n        self.left = left\n        self.right = right\n\nclass Add(BinaryOp):\n    def eval(self):\n        return self.left.eval() + self.right.eval()\n\nclass Sub(BinaryOp):\n    def eval(self):\n        return self.left.eval() - self.right.eval()\n\nclass Mul(BinaryOp):\n    def eval(self):\n        return self.left.eval() * self.right.eval()\n\nclass Div(BinaryOp):\n    def eval(self):\n        return self.left.eval() / self.right.eval()\n\n# 2. Build the Lexer\nlg = LexerGenerator()\n\nlg.add('NUMBER', r'\\d+')\nlg.add('PLUS', r'\\+')\nlg.add('MINUS', r'-')\nlg.add('MUL', r'\\*')\nlg.add('DIV', r'/')\nlg.add('OPEN_PAREN', r'\\(')\nlg.add('CLOSE_PAREN', r'\\)')\n\nlg.ignore(r'\\s+')\n\nlexer = lg.build()\n\n# 3. Build the Parser\npg = ParserGenerator(\n    ['NUMBER', 'PLUS', 'MINUS', 'MUL', 'DIV', 'OPEN_PAREN', 'CLOSE_PAREN'],\n    precedence=[('left', ['PLUS', 'MINUS']), ('left', ['MUL', 'DIV'])]\n)\n\n@pg.production('expression : NUMBER')\ndef expression_number(p):\n    return Number(int(p[0].getstr()))\n\n@pg.production('expression : OPEN_PAREN expression CLOSE_PAREN')\ndef expression_paren(p):\n    return p[1]\n\n@pg.production('expression : expression PLUS expression')\ndef expression_plus(p):\n    return Add(p[0], p[2])\n\n@pg.production('expression : expression MINUS expression')\ndef expression_minus(p):\n    return Sub(p[0], p[2])\n\n@pg.production('expression : expression MUL expression')\ndef expression_mul(p):\n    return Mul(p[0], p[2])\n\n@pg.production('expression : expression DIV expression')\ndef expression_div(p):\n    return Div(p[0], p[2])\n\n@pg.error\ndef error_handler(token):\n    raise ValueError(\"Ran into a %s where it wasn't expected\" % token.gettokentype())\n\nparser = pg.build()\n\n# 4. Use the Lexer and Parser\ntext = \"(10 + 5) * 2 / 3 - 1\"\ntokens = lexer.lex(text)\n\ntry:\n    result = parser.parse(tokens).eval()\n    print(f\"Result of '{text}': {result}\")\nexcept ParsingError as e:\n    print(f\"Parsing error at position {e.getsourcepos()}: {e}\")\nexcept ValueError as e:\n    print(f\"Error: {e}\")","lang":"python","description":"This quickstart demonstrates how to create a simple arithmetic expression parser using RPly. It covers defining tokens with `LexerGenerator`, creating an Abstract Syntax Tree (AST) using classes inheriting from `BaseBox`, and defining grammar rules and precedence with `ParserGenerator` to evaluate expressions.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"0.7.8","pypi_latest":"0.7.8","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.6,"avg_import_s":0.02,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"rply","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"18.0M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"rply","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"rply","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.03,"mem_mb":1.2,"disk_size":"19.8M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"rply","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0.03,"mem_mb":1.2,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"rply","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.03,"mem_mb":0.9,"disk_size":"11.7M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"rply","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.03,"mem_mb":0.9,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"rply","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"11.5M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"rply","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.02,"mem_mb":0.9,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"rply","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.02,"mem_mb":1.2,"disk_size":"17.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"rply","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.02,"mem_mb":1.2,"disk_size":"18M"}]}}