Registry / data / sql-metadata

sql-metadata

JSON →
library2.20.0pypypi✓ verified 35d ago

sql-metadata is a Python library that parses SQL queries to extract metadata such as table names, column names, query type (e.g., SELECT, INSERT, UPDATE, DELETE), and more. It leverages the tokenized query output from the `sqlparse` library. The current version is 2.20.0, and it maintains an active release cadence, often releasing minor versions to improve parsing accuracy and update its `sqlparse` dependency.

dataserialization
Install & Compatibility
Where this runs
tested against v2.20.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.058s · 18.3MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.6s · import 0.051s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from sql_metadata.parser import Parser

Initialize a Parser object with a SQL string to extract various metadata attributes.

from sql_metadata.parser import Parser sql_query = "SELECT id, name, email FROM users WHERE status = 'active' ORDER BY name;" parser = Parser(sql_query) print(f"Tables: {parser.tables}") print(f"Columns: {parser.columns}") print(f"Query Type: {parser.query_type}") print(f"Limit: {parser.limit}") print(f"Group by: {parser.group_by}")
Debug
Known footguns
breakingSupport for Python 3.8 was dropped in version 2.16.0. Users on Python 3.8 will need to upgrade their Python environment or pin sql-metadata to a version prior to 2.16.0.
gotchaThe `Parser.columns` method in version 2.20.0 contains a fix that causes a column named `source` to be dropped if it is the last column in a `SELECT` statement. This change in behavior might affect applications relying on specific column outputs for such edge cases.
gotchaParsing accuracy for specific SQL dialects and complex constructs (e.g., `ALTER TABLE ... ADD KEY`, MSSQL unqualified schema tables, `TRUNCATE TABLE`, Hive `CREATE FUNCTION`) has been incrementally improved across minor versions (e.g., v2.13.0, v2.14.0, v2.17.0, v2.12.0). Users on older versions might experience incorrect or incomplete metadata extraction for such queries.
gotchaThe library's parsing capabilities are highly dependent on the underlying `sqlparse` library. While `sql-metadata` manages its `sqlparse` dependency, breaking changes or parsing quirks in `sqlparse` can indirectly affect `sql-metadata`'s behavior and accuracy. Always check `sqlparse` release notes if `sql-metadata` updates its `sqlparse` dependency.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
17 hits · last 30 days
bytedance
5
gptbot
4
ahrefsbot
4
claudebot
4
Resources