Simple DDL Parser to parse SQL & dialects like HQL, TSQL (MSSQL), Oracle, AWS Redshift, Snowflake, MySQL, PostgreSQL, etc ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc.; sequences, alters, custom types & other entities from ddl.
—
CLI tool accessible via the sdp command for processing DDL files from the command line with various output options and batch processing capabilities. The CLI provides convenient access to all parser functionality without requiring Python programming.
Primary CLI function exposed as the sdp system command for command-line DDL parsing.
def main():
"""
Main CLI entry point exposed as 'sdp' command.
Handles command-line argument parsing and execution.
"""Create and configure the command-line argument parser with all available options.
def cli():
"""
Create and configure argument parser for CLI interface.
Returns:
ArgumentParser configured with all CLI options
"""Process individual DDL files with specified options and output formatting.
def run_for_file(args):
"""
Process a single DDL file with specified arguments.
Parameters:
- args: Parsed command-line arguments containing file path and options
"""Validate file extensions to ensure appropriate files are processed.
def correct_extension(file_name: str) -> bool:
"""
Check if file has a valid DDL file extension.
Parameters:
- file_name (str): Name of file to check
Returns:
bool: True if file has valid extension (.sql, .ddl, etc.)
"""# Parse a single DDL file
sdp schema.sql
# Parse with specific output dialect
sdp schema.sql --output-mode postgres
# Parse directory of DDL files (processes all .sql, .ddl, .hql, .bql files)
sdp /path/to/ddl/directory# Save output to custom directory (default: schemas/)
sdp schema.sql --target ./output
# Print results to console only (no file output)
sdp schema.sql --no-dump
# Enable verbose output to console
sdp schema.sql -v# MySQL-specific output
sdp mysql_schema.sql --output-mode mysql
# PostgreSQL-specific output
sdp postgres_schema.sql --output-mode postgres
# BigQuery-specific output
sdp bigquery_schema.sql --output-mode bigquery
# Oracle-specific output
sdp oracle_schema.sql --output-mode oracle
# Available output modes: sql, mysql, postgres, oracle, mssql, hql,
# snowflake, bigquery, redshift, spark_sql, databricks, sqlite,
# vertics, ibm_db2, athena# Input file: simple_table.sql
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(100) UNIQUE
);
# Command:
sdp simple_table.sql
# Result: Creates simple_table_schema.json in schemas/ directory# Parse and display results in terminal
sdp schema.sql -v
# Parse without creating files, only show in terminal
sdp schema.sql --no-dump# Save results to custom directory
sdp schema.sql --target ./my_output_dir
# Parse with specific dialect formatting
sdp postgres_schema.sql --output-mode postgres --target ./postgres_schemas# Process all DDL files in a directory
sdp /path/to/ddl/files/
# Process directory with verbose output
sdp /path/to/ddl/files/ -v --output-mode mysql# Process same schema for different target databases
sdp schema.sql --output-mode mysql --target ./mysql_output
sdp schema.sql --output-mode postgres --target ./postgres_output
sdp schema.sql --output-mode oracle --target ./oracle_outputThe CLI functionality can also be accessed programmatically:
from simple_ddl_parser.cli import main, cli, run_for_file
import sys
# Simulate CLI call
sys.argv = ['sdp', 'schema.sql', '--output-mode', 'postgres']
main()
# Or use individual functions
parser = cli()
args = parser.parse_args(['schema.sql', '--target', './output'])
run_for_file(args)Install with Tessl CLI
npx tessl i tessl/pypi-simple-ddl-parser