Simple DDL Parser

1.13.0 · active · verified Thu Apr 16

Simple DDL Parser is a Python library designed to parse SQL DDL (Data Definition Language) files from various dialects, including HQL, TSQL (MSSQL), Oracle, AWS Redshift, Snowflake, MySQL, and PostgreSQL. It extracts comprehensive information about database entities like tables, columns (types, defaults, primary keys), sequences, alters, and custom types into a JSON or Python dictionary format. The library is actively maintained with frequent releases, currently at version 1.13.0, and typically sees rapid updates with more than 12 releases per year.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a DDL statement using the `DDLParser` class. It shows a basic table creation and an example of parsing an HQL statement with the `output_mode='hql'` argument to extract dialect-specific details like `EXTERNAL` or `LOCATION`.

from simple_ddl_parser import DDLParser

ddl_statement = """
CREATE TABLE users (
    user_id INT PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    email VARCHAR(100),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
"""

parser = DDLParser(ddl_statement)
parsed_data = parser.run()

print(parsed_data)

# Example with dialect-specific output (e.g., HQL)
hql_ddl = """
CREATE EXTERNAL TABLE IF NOT EXISTS database.table_name (
    day_long_nm string,
    calendar_dt date,
    source_batch_id string
)
PARTITIONED BY (batch_id int)
STORED AS PARQUET
LOCATION 's3://datalake/table_name/v1';
"""
hql_parser = DDLParser(hql_ddl)
hql_parsed_data = hql_parser.run(output_mode='hql')
print(hql_parsed_data)

view raw JSON →