sly
"SLY - Sly Lex Yacc"
What it is and what it does
SLY is a pure-Python lexer and parser generator based on the LALR(1) algorithm, designed for building compilers and domain-specific language parsers without requiring a separate code generation step. You define lexer and parser rules as Python classes with decorators, and SLY handles tokenization and syntax analysis directly at runtime.
The library was originally developed for instructional purposes and emphasizes extensive error reporting to help users identify common mistakes. It supports empty productions, error recovery, precedence rules, and moderately ambiguous grammars. While not optimized for speed due to its Python implementation, it can handle grammars with several hundred rules. However, the project was retired on December 21, 2025, and no further maintenance is planned.
Use it for:
- Building a domain-specific language (DSL) interpreter or compiler without external code generation tools.
- Parsing configuration files or domain-specific syntax with custom error messages for invalid input.
- Educational projects where understanding parser construction and LALR theory is part of the goal.
- Prototyping language features or grammar designs before committing to a production parser generator.
- Embedding a simple expression evaluator into a Python application.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
SLY is a pure-Python implementation of lex and yacc for building lexers and parsers using LALR(1) parsing, with no code generation step required.
No—do not install for new projects. The project is formally retired as of December 21, 2025 with no planned maintenance. While the code is stable and license-permissive, the maintainer explicitly recommends considering alternatives. Install only if you are maintaining existing code that already depends on SLY, or if you are willing to fork and maintain it yourself.
Install
sly on PyPI
pip
pip install slyuv
uv add slypoetry
poetry add slyInstalling sly
Before you install
Installation is frictionless with no runtime dependencies. However, the project was formally retired on December 21, 2025, with the maintainer stating no further maintenance is expected. The repository is archived. Users should be aware they are adopting a library that will not receive updates or bug fixes.
License in practice
SLY is licensed under the MIT License (permissive), meaning you can use, modify, and distribute it freely with minimal restrictions, though you must include the license notice.
Quickstart
from sly import Lexer, Parser
class MyLexer(Lexer):
tokens = { NAME, NUMBER }
NAME = r'[a-zA-Z_][a-zA-Z0-9_]*'
NUMBER = r'\d+'
class MyParser(Parser):
tokens = MyLexer.tokens
@_('NUMBER')
def expr(self, p):
return int(p.NUMBER)
lexer = MyLexer()
parser = MyParser()
result = parser.parse(lexer.tokenize('text'))
Requires Python 3.6 or greater.
Verify before relying
- Whether the archived repository will accept security patches or critical bug fixes despite the retirement notice.
- Performance characteristics when parsing large or complex grammars in production settings.
- Compatibility with recent Python versions given the last release was October 2022.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,389 days since the last release |
| Last repo commit | (repository archived) |
| First released | |
| Downloads | 5,083,867/month — #2,172 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sly-0.5-py3-none-any.whl
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
funcparserlibFuncparserlib is a recursive descent parsing…
permissive · top 15,000 on PyPI
plyPLY is a lexer and parser generator for Python…
permissive · top 1,000 on PyPI
rplyRPLY is a pure Python parser generator that…
permissive · top 15,000 on PyPI
phplyphply is a lexer and parser for PHP source code…
permissive · top 15,000 on PyPI
pygmarsPygmars builds lightweight lexers and parsers…
permissive · top 15,000 on PyPI
lark-parserLark is a parsing library that builds abstract…
permissive · top 5,000 on PyPI
javalangjavalang is a pure Python lexer and parser for…
permissive · top 15,000 on PyPI
ParsleyParsley is a PEG-based parsing library that…
permissive · top 5,000 on PyPI
PyMeta3PyMeta3 compiles pattern-matching grammars…
permissive · top 15,000 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI