skillfed

moz-sql-parser

Extract Parse Tree from SQL

moz-sql-parser v4.40.21126 111.4K downloads/30d#12,418 on PyPI294
Copyleft license MPL 2.0 AGING released

What it is and what it does

Moz SQL Parser converts SQL SELECT queries into JSON-serializable parse trees, where each SQL clause becomes a named object property and expressions are represented as operation-parameter pairs. It also provides a formatter to generate SQL from JSON objects, though that feature remains incomplete. The parser originally targeted MySQL but has expanded to other vendors; it handles basic queries, subqueries, WITH clauses, and window functions, but does not support UPDATE or INSERT statements or provide data access tools.

The package is designed to let non-SQL datastores expose a familiar SQL interface to users, with the expectation that developers will convert the resulting JSON parse trees into native queries for their backend. It has no runtime dependencies, making installation straightforward, but the codebase is aging—the latest release is from May 2021 and maintenance appears minimal despite recent repository activity.

Use it for:

  • Convert SQL queries to JSON for analysis, validation, or transformation in a custom query engine or datastore adapter.
  • Build a SQL-to-native-query translator that accepts SQL input and generates backend-specific queries from the parse tree.
  • Analyze SQL query structure programmatically to extract table names, columns, or filter conditions.
  • Provide a SQL interface to non-relational datastores by parsing user queries and mapping them to native APIs.
  • Generate SQL statements from JSON configuration objects for dynamic query construction.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Parses SQL queries into JSON-serializable parse trees, and can generate SQL from JSON objects, supporting basic SELECT queries with clauses like WHERE, ORDER BY, and window functions.

Yes, if you need basic SQL parsing to JSON and can tolerate an aging codebase. The package has no dependencies, handles common SELECT patterns, and has been stable for years. However, install only if you do not require support for advanced SQL dialects or expect active maintenance; the latest release is from May 2021 and the project is classified as aging. The copyleft MPL 2.0 license requires source disclosure if you modify and redistribute.

Install

moz-sql-parser on PyPI

pip

pip install moz-sql-parser

uv

uv add moz-sql-parser

poetry

poetry add moz-sql-parser

Installing moz-sql-parser

Before you install

High install friction: the package has not been updated since May 2021 and is classified as aging. The last commit was in October 2025, but the latest release is nearly five years old, suggesting maintenance is minimal or stalled.

License in practice

Licensed under Mozilla Public License 2.0 (MPL 2.0), a copyleft license. You must disclose source code modifications and distribute under the same license if you modify and distribute the package; this may constrain commercial or proprietary use.

Quickstart

from moz_sql_parser import parse
import json
result = parse("select a, b from jobs where a > b")
print(json.dumps(result))

Python recursion limit may need adjustment for large or deeply nested SQL queries; the default limit may be insufficient.

Verify before relying

  • Whether the parser handles modern SQL dialects (BigQuery, Redshift, etc.) beyond basic SELECT—the description notes these are still missing.
  • Current state of test coverage and whether the tests mentioned have been maintained or expanded.
  • Whether the formatter (SQL generation from JSON) is production-ready or remains incomplete.

Package facts

License MPL 2.0 (copyleft)
Python support not specified
Install friction high — source build required
Runtime dependencies none
Maintenance aging — 1,926 days since the last release
Last repo commit
First released
Downloads 111,380/month — #12,418 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: moz-sql-parser-4.40.21126.tar.gz

Development Status :: 3 - AlphaLicense :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)Programming Language :: Python :: 3.7Programming Language :: SQLTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python Modules

Tags

sql parser to jsonparse sql queriessql to parse treesql query analysisconvert sql to jsonsql syntax parsingquery tree extraction
sql-parsingquery-analysisjson-serialization

More Libraries packages