PYPI PACKAGE AUDIT v0.6.1 企业级健康

sqlparse

A non-validating SQL parser.

PyPkgScore sqlparse
评估方法与标准 ♥ Donate
905 / 1000
快速安装
pip install sqlparse
1. 治理
200/200
2. PEP 元数据
200/200
3. 安全性
150/200
4. 文档与 SEO
155/200
5. CI 工程
200/200
📣 分享审计报告: 以当前语言分享此报告和可视化卡片
Advertisement
PyPI 遥测数据

下载量与社区采用率

最近 30 天(不含镜像)
最近 7 天
31089376
最近 30 天
130262482
总计(180天)
786983609
指标 / 生态系统 状态 / 数值 来源
Downloads (30d / 180d) — PyPI Stats (without mirrors)
Trusted Publishing (PEP 740) ✕ Not detected PyPI Integrity / Sigstore
Django Packages — djangopackages.org
PyTech / PyPkgScore 905 / 1000 PyPkgScore Engine

健康与工程分析(5大支柱)

1. 治理与社区200 / 200 ▾
LICENSE✓ 50 pts
SECURITY.md✓ 50 pts
CONTRIBUTING.md✓ 50 pts
CODE_OF_CONDUCT.md✓ 50 pts
2. PEP 元数据与打包200 / 200 ▾
Wheel (.whl)✓ 50 pts
pyproject.toml✓ 50 pts
Project URLs✓ 50 pts
Trove Classifiers✓ 50 pts
3. 安全与供应链150 / 200 ▾
零 CVE 漏洞 (OSV)✓ 60 pts
Trusted Publishing (OIDC)✕ 0 pts
Snyk / Audit Link✓ 40 pts
HTTPS 代码仓库✓ 50 pts
4. 文档、SEO 与生态系统155 / 200 ▾
结构化 README✓ 60 pts
Read the Docs✓ 50 pts
Django Packages✕ 0 pts
网站 / 技术文章✓ 45 pts
5. 工程、CI 与代码质量200 / 200 ▾
自动化测试✓ 65 pts
GitHub Actions CI✓ 65 pts
CHANGELOG.md✓ 35 pts
Lockfile (rye/uv/poetry)✓ 35 pts
Advertisement
README & DOCS

Documentação Oficial & Guia de Uso — sqlparse

PyPI Metadata v0.6.1
Exibir documentação original completa (README em Inglês) ▾

sqlparse

Build Status Coverage Documentation PyPI Python versions License

[!IMPORTANT] Project Status: End of Maintenance

sqlparse is no longer actively maintained. Version 0.6.1 was its final release.

No further bug fixes, feature updates, or security fixes are planned. The repository and published packages will remain available, but users should not expect ongoing maintenance or security support.

Software Supply Chain Security: To minimize supply chain risks, I will retain control of the sqlparse project on PyPI and this GitHub repository. There are no plans to transfer ownership or grant publishing or commit access to third parties.

After many years of maintaining sqlparse as a volunteer, I have decided to bring the project to a close. A more detailed explanation of this decision is available separately.

THANKS TO ALL USERS AND CONTRIBUTORS! I would like to thank everyone who has contributed to sqlparse over the years.

A non-validating SQL parser for Python. Split scripts into statements, format them, and walk their token tree.

sqlparse tokenizes SQL text and groups the parts it recognizes into a tree of statements, clauses, identifiers and expressions. It accepts any input without validating it, and makes no assumptions about a particular SQL dialect, so vendor extensions and templated SQL parse too. It is a building block for formatters, linters, editors and query analysis tools.

Licensed under the New BSD license.

Install

pip install sqlparse

Usage

Three module-level functions cover most needs: split(), format() and parse().

Split a script into statements

import sqlparse

sqlparse.split("select * from foo; select * from bar;")
# ['select * from foo;', 'select * from bar;']

Format a statement

print(sqlparse.format("select id,name from users where active=1",
                      reindent=True, keyword_case="upper"))
SELECT id,
       name
FROM users
WHERE active=1

format() accepts the same options as the command line, among them reindent, keyword_case, strip_comments and indent_width.

Parse and inspect a statement

statement = sqlparse.parse("select id, name from users where active = 1")[0]

print(statement.get_type())
for token in statement.tokens:
    if not token.is_whitespace:
        print(f"{token.ttype or type(token).__name__!s:20} {token!s}")
SELECT
Token.Keyword.DML    select
IdentifierList       id, name
Token.Keyword        from
Identifier           users
Where                where active = 1

Tokens with a ttype are leaves. The others are groups you can descend into, which is how nested constructs like subqueries and CASE expressions are represented. See Analyzing SQL statements for the traversal API.

Command line

Installing sqlparse also provides the sqlformat command. It reads from stdin when the filename is -, writes to stdout by default, and rewrites files in place with --in-place:

sqlformat --reindent --keywords upper query.sql

Run sqlformat --help for all formatting options.

Pre-commit hook

Format SQL files on commit with pre-commit:

repos:
  - repo: https://github.com/andialbrecht/sqlparse
    rev: 0.5.5  # use the latest release
    hooks:
      - id: sqlformat
        args: [--in-place, --reindent, --keywords, upper]

The hook defaults to --in-place --reindent. When overriding args, keep --in-place, or the hook writes to stdout and leaves your files unchanged.

Links

Documentation https://sqlparse.readthedocs.io/
Release notes https://sqlparse.readthedocs.io/en/latest/changes.html
Issues https://github.com/andialbrecht/sqlparse/issues
Discussions https://github.com/andialbrecht/sqlparse/discussions
Online demo https://sqlformat.org/

Contributing

Contributions are welcome. See CONTRIBUTING.md to get started.

sqlparse is maintained in spare time, so it can take a while before an issue or pull request gets a reply. Thanks for your patience. A pull request that comes with tests for the behavior it changes is usually the quickest to review.

For security issues, please follow SECURITY.md rather than opening a public issue.

License

sqlparse is licensed under the New BSD license; see LICENSE for the full text. Parts of the code are based on Pygments, written by Georg Brandl and others.