Install & Compatibility
Where this runs
tested against v11.697.25301 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.117s · 18.9MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.8s · import 0.113s · 19MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
parse
✓ from mo_sql_parsing import parse
✗ from moz_sql_parser import parse
The 'moz_sql_parser' library is deprecated; 'mo-sql-parsing' is an actively maintained fork.
parse_sqlserver
✓ from mo_sql_parsing import parse_sqlserver
Use this for SQLServer-specific syntax, especially identifier handling with square brackets '[]'.
parse_mysql
✓ from mo_sql_parsing import parse_mysql
Use this for MySQL-specific syntax, such as handling double-quotes for literal strings.
The `mo_sql_parsing` library's primary function is `parse`, which takes a SQL string and returns a JSON-like Python dictionary representing the parse tree. Specialized parsers like `parse_sqlserver` and `parse_mysql` are available for dialect-specific syntax.
from mo_sql_parsing import parse
# Basic SELECT query
sql_query = "select count(1) from jobs"
parsed_json = parse(sql_query)
print(f"Parsed basic query: {parsed_json}")
# Expected: {'select': {'value': {'count': 1}}, 'from': 'jobs'}
# SELECT with aliases
sql_query_aliases = "select a as hello, b as world from jobs"
parsed_json_aliases = parse(sql_query_aliases)
print(f"Parsed query with aliases: {parsed_json_aliases}")
# Expected: {'select': [{'value': 'a', 'name': 'hello'}, {'value': 'b', 'name': 'world'}], 'from': 'jobs'}
# Example with SQLServer-specific parsing
from mo_sql_parsing import parse_sqlserver
sqlserver_query = "SELECT [Timestamp] FROM [table]"
parsed_sqlserver = parse_sqlserver(sqlserver_query)
print(f"Parsed SQLServer query: {parsed_sqlserver}")
# Expected: {'select': 'Timestamp', 'from': 'table'}
Debug
Known issues
breakingThe `mo-sql-parsing` library is a fork of the now-archived `moz-sql-parser`. Users migrating from `moz-sql-parser` must update their package installations and import paths (`moz_sql_parser` to `mo_sql_parsing`).fixUninstall `moz-sql-parser` and install `mo-sql-parsing`. Update import statements: `from mo_sql_parsing import parse`.
affects: All versions (migration from `moz-sql-parser` to `mo-sql-parsing`)
gotchaSquare brackets `[]` have different meanings in SQL dialects (e.g., identifiers in SQLServer, array constructors in BigQuery). Using the default `parse` function for SQLServer queries might lead to incorrect interpretations.fixFor SQLServer syntax, explicitly use `from mo_sql_parsing import parse_sqlserver as parse` to ensure correct parsing of identifiers.
affects: All versions
gotchaBy default, SQL `NULL` values are parsed into `{'null':{}}` in the output JSON tree, not Python's `None`.fixIf Python's `None` is desired for `NULL` values, pass the `null=None` argument to the `parse` function: `parse(sql_query, null=None)`.
affects: All versions
gotchaThis library relies on `mo-parsing` (a fork of `pyparsing`) internally. There are behavioral differences between `mo-parsing` and upstream `pyparsing`, notably how `add_parse_action()` creates new `ParserElement` objects that must be assigned, and `ParserElements` being static. Direct application of `pyparsing` idioms may not work.fixConsult the `mo-parsing` documentation for specific differences, especially regarding how parser actions modify grammar elements. For `add_parse_action()`, ensure the result is assigned back to the variable.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'moz_sql_parser'
The old `moz-sql-parser` library is not installed or the import path is incorrect. `mo-sql-parsing` is its successor.
fixInstall `mo-sql-parsing` (`pip install mo-sql-parsing`) and update import statements to `from mo_sql_parsing import parse`.
Unexpected JSON output for SQL 'NULL' as {'null': {}} instead of None.
The default behavior of `mo-sql-parsing` is to represent SQL `NULL` as a dictionary `{'null':{}}` in the parse tree.
fixTo get Python's `None` for SQL `NULL`, call the `parse` function with the `null` argument: `result = parse(sql, null=None)`.
SQL queries with square brackets like `SELECT [col] FROM [tbl]` are not parsed correctly; they might be interpreted as array literals.
The default parser often assumes a BigQuery-like dialect where `[]` denotes array constructors. This conflicts with SQLServer's use of `[]` for identifiers.
fixImport and use the `parse_sqlserver` function explicitly for SQLServer queries: `from mo_sql_parsing import parse_sqlserver as parse`.
Upgrade
Version history
11.697.25301latest on PyPI · released Oct 28, 2025
Audit
Dependencies
mo-dotsrequiredCore utility dependency
mo-futurerequiredCore utility dependency
mo-parsingrequiredForked pyparsing for faster parsing, fundamental for SQL grammar definition
mo-importsrequiredCore utility dependency