a Python port of sqlparser for Rust
use correct link
added a bare-bones README


browse log



A Python port of sqlparser for Rust

This is alpha code. It passes all of the original regression tests but it had not otherwise been used in earnest.

Parts of the API are subject to change, mostly in how to deal with dialects. (The current class-based/metaclass system is awkward.)

There are several differences from the original Rust code:

  1. More of the tokenizer code is pushed into the dialects, using a PLY-style regex match system.

  2. Some of the class-based objects (like DataType.Int) are made into instances (like DataType.Int()).

  3. Statement.Function is a subclass of Statment and Function, reducing a level of boxing.

  4. A lot of the boxing in the Rust code is ignored. Some is handled via a has-a attribute.

  5. Some of the variables are renamed, like from to from_. OffsetRows::None

  6. I don't know Rust, so I've had to guess at a number of things.


There is no installation method. You have to run it in the top-level directory of the checkout.

Here's an example of it in work:

% python -m sqlparserpy --sql 'select a.c from a, b where sqrt(a*b) < 1.0' | fold -w 72
=== repr ===
[0]: Query(with_=None, body=Select(distinct=False, top=None, projection=
='a', quote_style=None), Ident(value='c', quote_style=None)]))], from_=[
nts=[Ident(value='a', quote_style=None)]), alias=None, args=[], with_hin
ts=[]), joins=[]), SelectItem_TableWithJoins(relation=TableFactor_Table(
name=ObjectName(idents=[Ident(value='b', quote_style=None)]), alias=None
, args=[], with_hints=[]), joins=[])], lateral_views=[], selection=Expr_
quote_style=None)]), args=[FunctionArg_Unnamed(unnamed_arg=Expr_BinaryOp
(left=Expr_Identifier(ident=Ident(value='a', quote_style=None)), op=Bina
ryOperator_Multiply(op='*'), right=Expr_Identifier(ident=Ident(value='b'
, quote_style=None))))], over=None, distinct=False), op=BinaryOperator_L
t(op='<'), right=Expr_Value(value=Value_Number(value='1.0', is_long=Fals
e))), group_by=[], cluster_by=[], distribute_by=[], sort_by=[], having=N
one), order_by=[], limit=None, offset=None, fetch=None)

=== to_file() ===
-- statement [0]:
SELECT a.c FROM a, b WHERE sqrt(a * b) < 1.0;


Many, many thanks to the authors of and contributers to the sqlparser-rs project!

This port was done by Andrew Dalke <dalke@dalkescientific.com>.