# 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:

```bash
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](<https://sqlty.kuncar.dev/installation/#python-package-or-native-executable>) instead: `npx @sqlty/cli check` or `brew install jirikuncar/sqlty/sqlty`.

To try the command without adding anything:

```bash
uvx sqlty check .
```

Extras add the [psycopg](<https://sqlty.kuncar.dev/guide/psycopg/index.md>) and [rustmy](<https://sqlty.kuncar.dev/guide/rustmy/index.md>) helpers: `uv add 'sqlty[psycopg]'`.

## 2\. Point it at your schema

`pyproject.toml`:

```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](<https://sqlty.kuncar.dev/guide/schema-inference/index.md>) and [Configuration](<https://sqlty.kuncar.dev/reference/configuration/index.md>).

## 3\. Type and check the queries

Start each query string with `--sql` and a newline, then:

```bash
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](<https://sqlty.kuncar.dev/quickstart/index.md>) walks through one file.

## 4\. Editor

| Editor | Setup |
| --- | --- |
| VS Code, Cursor, VSCodium | `code --install-extension jirikuncar.sqlty`, see [VS Code](<https://sqlty.kuncar.dev/recipes/vscode/index.md>) |
| Neovim, Vim, Helix, Emacs | `sqlty server` as a language server, see [Neovim, Vim, Helix and Emacs](<https://sqlty.kuncar.dev/recipes/editors/index.md>) |

The editor runs the `sqlty` of your project's environment, so it reports what CI reports.

## 5\. Pre-commit and CI

```yaml
# .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](<https://sqlty.kuncar.dev/recipes/ci/index.md>) adds the pre-commit hooks, `sqlty breaking` for migrations and SARIF for code scanning.

## 6\. Coding agents

```text
/plugin marketplace add jirikuncar/sqlty
/plugin install sqlty@sqlty
```

That is Claude Code; [Coding agents](<https://sqlty.kuncar.dev/recipes/agents/index.md>) 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](<https://sqlty.kuncar.dev/guide/drivers-and-orms/index.md>).
