sqlite_parser/__init__.py annotated source
Back to indexPublic API Module
This module defines the public interface for the sqlite-ast-parser package. It exports the main entry points and key classes that users need to interact with the parser.
Primary Functions
The parser provides two main entry points:
-
parse_sql(sql: str) -> List[Statement]: The main parsing function that takes SQL text and returns a list of AST statement nodes. This is what most users will call. -
tokenize_sql(sql: str) -> List[Token]: Lower-level function that performs only tokenization, returning a list of tokens without building an AST. Useful for debugging or building custom parsers.
Usage Pattern
```python from sqlite_parser import parse_sql
sql = "SELECT id, name FROM users WHERE age > 18" statements = parse_sql(sql)
for stmt in statements:
stmt is a SelectStatement node
print(stmt.select_core.from_clause) ```
What's Exported
- Main API:
parse_sql,tokenize_sql - Core Classes:
Lexer,Token(for advanced usage) - All AST Nodes: Every statement and expression node type (via
*import) - Error Classes: For exception handling
- Version: Package version string
3738"""39SQLite SQL Parser4041A complete, production-ready SQLite SQL parser that returns detailed Abstract Syntax Trees (AST).4243Example usage:44 from sqlite_parser import parse_sql4546 sql = "SELECT id, name FROM users WHERE age > 18"47 ast = parse_sql(sql)4849 for statement in ast:50 print(statement)51"""5253from .parser import parse_sql, tokenize_sql54from .lexer import Lexer, Token55from .ast_nodes import *56from .errors import (57 ParseError,58 LexerError,59 SyntaxError,60 UnexpectedTokenError,61 UnexpectedEOFError62)6364__version__ = "0.1.0"65__all__ = [66 # Main API67 "parse_sql",68 "tokenize_sql",69 # Core classes70 "Lexer",71 "Token",72 # Errors73 "ParseError",74 "LexerError",75 "SyntaxError",76 "UnexpectedTokenError",77 "UnexpectedEOFError",78 # All AST nodes are exported via *79]80