andialbrecht/sqlparse
andialbrecht/sqlparse has 4,023 GitHub stars and 779 forks. GitHot measured 0 stars in 24 hours and +1 in 7 days. Last checked 2026-11-07 05:58 UTC. Last push 2026-11-01.
Python용 비검증 SQL 파서 모듈
측정된 스타 증가
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- 기록 수집 중
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalsqlparse
[!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.
관련 프로젝트 살펴보기
Asabeneh/30-Days-Of-Python
30 Days of Python 프로그래밍 챌린지는 Python 프로그래밍 언어를 30일 동안 배우기 위한 단계별 가이드입니다. 이 챌린지는 100일 이상 걸릴 수 있습니다. 자신의 속도에 맞춰 진행하세요. 다음 동영상도 도움이 될 수 있습니다: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,303 스타grafana/grafana
개방적이고 조합 가능한 옵저버빌리티 및 데이터 시각화 플랫폼입니다. Prometheus, Loki, Elasticsearch, InfluxDB, Postgres 등 여러 소스의 메트릭, 로그, 트레이스를 시각화합니다.
77,725 스타redis/redis
실시간 데이터 기반 애플리케이션을 구축하는 개발자에게 Redis는 가장 선호되고, 가장 빠르며, 기능이 가장 풍부한 캐시, 데이터 구조 서버이자 문서 및 벡터 쿼리 엔진입니다.
77,268 스타apache/superset
Apache Superset는 데이터 시각화 및 데이터 탐색 플랫폼입니다.
75,439 스타