Install sqlty for Python¶
From an empty project to typed queries checked in CI. Each step links to its full page.
1. Install¶
Your code imports sqlty for SQL[T], so add it to the project's dependencies:
uv add sqlty # or: pip install sqlty / poetry add sqlty
It needs Python 3.14 or 3.15. On an older Python, run the
native executable instead:
npx @sqlty/cli check or brew install jirikuncar/sqlty/sqlty.
To try the command without adding anything:
uvx sqlty check .
Extras add the psycopg and rustmy helpers:
uv add 'sqlty[psycopg]'.
2. Point it at your schema¶
pyproject.toml:
[tool.sqlty]
schema = "schema.sql" # CREATE TABLE statements, a pg_dump, or a migrations directory
dialect = "postgres" # or "mysql", "sqlite", ...
Without a schema, sqlty reads types from casts in the query. See Schema inference and Configuration.
3. Type and check the queries¶
Start each query string with --sql and a newline, then:
sqlty rewrite . # wraps each query as SQL[T] with its row type
sqlty check . # reports queries that no longer match the schema or T
The Quickstart walks through one file.
4. Editor¶
| Editor | Setup |
|---|---|
| VS Code, Cursor, VSCodium | code --install-extension jirikuncar.sqlty, see VS Code |
| Neovim, Vim, Helix, Emacs | sqlty server as a language server, see Neovim, Vim, Helix and Emacs |
The editor runs the sqlty of your project's environment, so it reports what CI reports.
5. Pre-commit and CI¶
# .github/workflows/sqlty.yml
name: sqlty
on: [pull_request]
jobs:
sqlty:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v7
- run: uv sync
- run: uv run sqlty check --output-format github .
CI and pre-commit adds the pre-commit hooks, sqlty breaking for
migrations and SARIF for code scanning.
6. Coding agents¶
/plugin marketplace add jirikuncar/sqlty
/plugin install sqlty@sqlty
That is Claude Code; Coding agents covers Codex, Cursor, Copilot
and sqlty skill --install.
Common questions¶
Should sqlty be a dev dependency?¶
Not when your code imports SQL from sqlty: that import runs in production. When the
code keeps plain --sql strings and you only run the command, a dev dependency is enough:
uv add --dev sqlty.
Does sqlty work with mypy, pyright and ty?¶
Yes. SQL[T] is a str subclass with a row type, so each type checker sees what a query
returns, and sqlty check keeps T in line with the SQL.
Which drivers does sqlty type?¶
Types follow psycopg 3 for PostgreSQL, PyMySQL for MySQL and sqlite3 for SQLite, with
driver = "asyncpg" for asyncpg. The raw SQL of SQLAlchemy and Django is typed too. See
Drivers and ORMs.