hayate-sql
Hayate ecosystem: Start here · Production golden app · Tested compatibility
Native SQL with a checked, typed execution boundary — not an ORM and not a query builder.
hayate-sql keeps each database's SQL, placeholders, plans, and transaction
semantics intact. A small contract above each statement adds named application
arguments, result cardinality, result shape, timeout, and parameter-free
telemetry.
Status: alpha (0.1.x), typed. SQLite, Cloudflare D1, and asyncpg-compatible PostgreSQL execution are implemented. SQLite/D1 contracts can be compiled against an in-memory schema; PostgreSQL contracts can be prepared against an ephemeral PostgreSQL transaction. The design memo (Japanese, per project convention) is in DESIGN.md.
Install
uv add hayate-sql
# Include asyncpg when PostgreSQL is the target.
uv add "hayate-sql[postgres]"
Write SQL
One .sql file contains one database-native statement:
-- name: get_document :one?
-- param: workspace_id str
-- param: document_id UUID
-- column: id UUID
-- column: title str
-- column: body str
-- timeout: 50ms
SELECT id, title, body
FROM documents
WHERE workspace_id = ?1
AND id = ?2
The placeholder syntax belongs to the target database. Use ?1 for
SQLite/D1 and $1 for PostgreSQL. The declared parameter order maps named
Python arguments to those native positions.
Cardinality is explicit:
:one— exactly one row:one?— zero or one row:many— zero or more rows:exec— no result rows; returnsCommandResult
Supported contract types are str, int, float, bool, bytes, object,
Any, datetime, date, Decimal, and UUID. Append ? for a nullable
value. Types generate Python annotations; runtime enforcement intentionally
checks the result's column shape rather than pretending that SQLite and
PostgreSQL use identical value representations. Declarations must therefore
describe the target driver's returned Python values (for example, a raw
SQLite boolean column is normally declared as int unless the SQL converts it).
Compile and generate
Compile D1/SQLite SQL against the real schema without executing queries:
hayate-sql check queries/ --dialect d1 --schema schema.sql
For PostgreSQL, prepare every query inside a transaction that is always
rolled back:
HAYATE_SQL_DATABASE_URL=postgresql://localhost/app_test \
hayate-sql check queries/postgres/ \
--dialect postgres \
--schema schema.sql
Generate a typed facade:
hayate-sql generate queries/ -o app/queries.py
The generated module intentionally uses only Python 3.12+ syntax and does not force postponed annotations. Run the project's formatter after generation when its style policy is stricter than the standard output.
The generated function has named arguments and a TypedDict result:
document = await queries.get_document(
database,
workspace_id=workspace_id,
document_id=document_id,
)
Generated code is a build artifact. SQL remains the source of truth.
Check against migration history
When forward-only SQL migrations are the schema source of truth, replay them in order before compiling the queries:
hayate-sql check queries/ --dialect d1 --migrations migrations/
Migration files use a fixed-width positive number followed by a lowercase
description, for example 0001_create_documents.sql. Gaps are allowed, while
duplicate versions, mixed widths, malformed names, and empty migrations fail
the check.
The migrations run only in hayate-sql's disposable check database. Applying
them to development, staging, or production remains the responsibility of the
database-native tool, such as wrangler d1 migrations apply or Alembic.
Execute
SQLite
from hayate_sql.adapters import SQLiteDatabase
async with SQLiteDatabase("app.db") as database:
async with database.transaction(mode="immediate"):
await queries.create_document(
database,
document_id=document_id,
title=title,
)
Cloudflare D1
from hayate_sql.adapters import D1Database
database = D1Database(context.env.DB)
# D1 consistency is explicit rather than hidden behind a generic transaction.
session = database.with_session("first-primary")
document = await queries.get_document(
session,
workspace_id=workspace_id,
document_id=document_id,
)
bookmark = session.bookmark()
The repository's reproducible workerd probe builds the 0.1.0 wheel, injects
that wheel into the Python Workers bundle, applies a real local D1 migration,
and executes :one, :one?, :many, and :exec:
bash scripts/check_workers_d1.sh
The same probe asserts that telemetry contains neither SQL text nor a sentinel bound value.
PostgreSQL
import asyncpg
from hayate_sql.adapters import AsyncpgDatabase
connection = await asyncpg.connect(dsn)
database = AsyncpgDatabase(connection)
# Delegates to asyncpg's native transaction context.
async with database.transaction(isolation="serializable"):
await queries.update_document(database, document_id=document_id, title=title)
Observe without leaking parameters
An observer receives only the query name, contract fingerprint, duration, success, row count, and error type. SQL text and bound values are deliberately absent.
def observe(event):
metrics.histogram("db.query.duration", event.duration_ms, query=event.name)
database = SQLiteDatabase("app.db", observer=observe)
Non-goals
- ORM models, identity maps, lazy relations, or repositories
- a database-independent SQL DSL or query builder
- SQL dialect translation
- a universal transaction abstraction
- production migration application, implicit schema migration, or write retries
License
MIT
Metadata
Release files for hayate-sql 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| hayate_sql-0.1.2.tar.gz | 14.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hayate_sql-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.1 kB
Release files / hayate_sql-0.1.2.tar.gz
| Download URL | hayate_sql-0.1.2.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f6891901d257f5419ccb99d5c5a21740a8f4f7814ca48009e47fea420ac480c8
|
|
BLAKE2b-256 checksum How to use checksums |
26dff6bf75d1881889d8cd87048ce97e4acf698ba73335ba38642c57de0e2a78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logRelease files / hayate_sql-0.1.2-py3-none-any.whl
| Download URL | hayate_sql-0.1.2-py3-none-any.whl |
|---|---|
| Size | 20.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02ff10996779ade9889e373691382d2e9049b56c323c7a80914cffb929006522
|
|
BLAKE2b-256 checksum How to use checksums |
cf78e747ca2faed9493cef8723223075b8353eb619751763010bfcc3941fef68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logSecurity for hayate-sql 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for hayate_sql-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.