SQLLineage is a Python library designed for SQL lineage analysis, capable of identifying source and target tables, as well as providing column-level lineage from SQL queries. It leverages popular SQL parser libraries like sqlfluff and sqlparse, and uses networkx for graph representation. The library is actively maintained, with its current version being 1.5.7, and sees regular minor releases to introduce enhancements and bug fixes.
pip install sqllineageVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `LineageRunner` with a SQL statement and extract the source and target tables. For accurate column-level lineage, especially with `SELECT *` or unqualified columns, providing a `MetaData` object (e.g., via `DummyMetaDataProvider` or `SQLAlchemyMetaDataProvider`) is crucial.
Always explicitly pass the `dialect` parameter to `LineageRunner` or the CLI for your specific SQL dialect (e.g., `sparksql`, `hive`, `tsql`) to ensure correct parsing, especially for complex or dialect-specific SQL. Use `sqllineage --dialects` to see available options.
Provide a `MetaData` object or use a `MetaData` provider (like `SQLAlchemyMetaDataProvider`) to `LineageRunner`. This allows `sqllineage` to access schema details and fully resolve column-level lineage.
Upgrade your Python environment to a supported version (e.g., Python 3.10 to 3.14 for `v1.5.7`). Check the official documentation for the latest Python compatibility matrix.
For highly complex or non-standard SQL, manual inspection and possibly pre-processing the SQL (e.g., by expanding templates, normalizing vendor-specific syntax) may be necessary to improve lineage accuracy. Providing a `MetaData` provider is also crucial for such cases.
pip install sqllineage
Access the input tables using `result.read` and output tables using `result.write`.
Use one of the officially supported dialects such as `'ansi'`, `'bigquery'`, `'databricks'`, `'hive'`, `'mssql'`, `'mysql'`, `'postgres'`, `'redshift'`, `'snowflake'`, `'sparksql'`, or `'tsql'`.
Install `sqllineage` with the `sqlfluff` extra using `pip install sqllineage[sqlfluff]` or install `sqlfluff` separately via `pip install sqlfluff`.