d2
A Python ORM built around a powerful, type-safe query builder. Define your schema as classes and build SELECT/INSERT/UPDATE/DELETE queries that your type checker understands — column references, filters, and results are all statically typed.
- Type-safe query builder — immutable, chainable builders where columns and results are typed end to end
- Declarative schema — define tables and views as Python classes with type annotations
- Integrated migrations — schema diffing, codegen, apply/rollback, lint checks
- Async execution — runs on asyncpg today, with results deserialised via msgspec
d2 currently targets PostgreSQL, but the query builder is dialect-agnostic by design, with support for more databases and drivers planned.
Documentation: https://okanakbulut.github.io/d2/
Installation
Requires Python 3.14+ and PostgreSQL.
pip install d2
Quick example
from d2 import Table, Field, PrimaryKey, Unique, field, db
class User(Table):
id: PrimaryKey[int] = field(default=db.serial())
name: Field[str]
email: Unique[str]
q = (
User
.select(User.id, User.name)
.where(User.email.ilike("%@example.com"))
.order_by(User.id)
.limit(10)
)
q.build()
# ('SELECT "user"."id","user"."name" FROM "public"."user"
# WHERE "user"."email" ILIKE $1 ORDER BY "user"."id" ASC LIMIT 10',
# ('%@example.com',))
See Getting Started for configuration, connections, and running your first migration.
License
Metadata
Release files for d2 0.11.0
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 | Actions |
|---|---|---|---|---|
| d2-0.11.0.tar.gz | 194.3 kB | With provenance | Details for d2-0.11.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| d2-0.11.0-py3-none-any.whl | Python 3 | none | any | Details for d2-0.11.0-py3-none-any.whl |
Total release size: 240.1 kB
Release files / d2-0.11.0.tar.gz
| Download URL | d2-0.11.0.tar.gz |
|---|---|
| Size | 194.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a15961d3ed1f3b1e097bcab4c218f1e22453a71965b4843135ab5869584b5bf
|
|
BLAKE2b-256 checksum How to use checksums |
88180bd4b7914fcebaf2faae8e6a22646244b1ab13f1da98d1dc8f8c553d1d01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 3, 2026.
Transparency logRelease files / d2-0.11.0-py3-none-any.whl
| Download URL | d2-0.11.0-py3-none-any.whl |
|---|---|
| Size | 45.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ee0fa0dfc2df2e7499e290f222315c8cdbeadff499d290856bf091205f8a7168
|
|
BLAKE2b-256 checksum How to use checksums |
d61b08786b652c6129a32cbb88eaca8c4193ebed7af803c66864f420e13b693e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 3, 2026.
Transparency logSecurity for d2 0.11.0
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
Both files in this release have been uploaded with provenance metadata.
Attestation for d2-0.11.0.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 Dec 3, 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.