sqlspec

Implements type-safe SQL query mapping across 15+ database adapters in Python.

Updated Aug 17, 2026
One-click install
npx skills add https://github.com/renjianguo666/litecms --skill sqlspec-renjianguo666
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlspec
Source: https://github.com/renjianguo666/litecms/tree/main/.agents/skills/sqlspec
Command: npx skills add https://github.com/renjianguo666/litecms --skill sqlspec-renjianguo666

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing raw SQL against heterogeneous databases forces developers to juggle different drivers, parameter styles, and connection lifecycles. This Skill provides guidance for SQLSpec, a type-safe SQL query mapper (not an ORM) that unifies 15+ database adapters behind one interface with a sqlglot-powered AST pipeline for validation and dialect conversion. ## Core Features & Use Cases - Unified Adapter Layer: Configure asyncpg, psycopg, SQLite, DuckDB, Oracle, BigQuery, Spanner, and more with consistent driver methods like select_one(), select_many(), and select_to_arrow(). - Query Builder & SQL Files: Build dynamic queries fluently with sql.select() or load static SQL from files via SQLFileLoader with caching. - Framework Integrations: First-party plugins for Litestar, FastAPI, Flask, and Starlette with dependency injection, commit-mode middleware, and filter providers. - Use Case: Build a FastAPI endpoint that paginates orders from PostgreSQL using provide_session() and provide_filters(), with automatic commit on 2xx responses and typed Pydantic results. ## Quick Start Ask the AI to set up an asyncpg adapter with a typed model and run a parameterized paginated query using SQLSpec.

Frequently Asked Questions about sqlspec

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run parameterized SQL queries in Python with SQLSpec?

Configure a typed adapter like AsyncpgConfig, then use async with config.create_driver() to get a driver and call methods like select_many() with your SQL and parameters. Match the parameter style to your adapter: $1 for asyncpg, %s for psycopg, ? for sqlite, and :name for oracledb.

What is the difference between SQLSpec and an ORM like SQLAlchemy?

SQLSpec is a type-safe SQL query mapper, not an ORM. It gives you direct SQL control, a fluent query builder, and 15+ driver adapters with Arrow support, while ORMs like SQLAlchemy or advanced-alchemy provide repository patterns, identity mapping, and attribute-style row access.

Does SQLSpec support FastAPI dependency injection?

Yes, the FastAPI extension provides Depends-based factories: provide_session() injects a per-request driver session and provide_filters() generates query-parameter-driven filter dependencies. Configuration lives under extension_config["starlette"] since the FastAPI plugin extends the Starlette plugin.

How do I paginate query results with SQLSpec filters?

Pass LimitOffsetFilter and OrderByFilter objects directly to driver methods like select_many() alongside your SQL string. Filters are composable, applied in order, and modify the statement before execution without manual LIMIT/OFFSET string concatenation.

Can SQLSpec return query results as Apache Arrow tables?

Yes, select_to_arrow() returns a pyarrow.Table with zero-copy transfer on DuckDB, ADBC, BigQuery, and Spanner adapters; other adapters convert rows to Arrow. Use copy_from_arrow() for bulk loading Arrow data back into a database table.

Why did my database write roll back after a 422 response in SQLSpec?

The autocommit middleware commits only on 2xx responses and rolls back everything else, including 4xx. Add the status code to extra_commit_statuses in extension_config, or switch commit_mode to manual and manage transactions explicitly.