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 "users"."id","users"."name" FROM "public"."users"
# WHERE "users"."email" ILIKE $1 ORDER BY "users"."id" ASC LIMIT 10',
# ('%@example.com',))
See Getting Started for configuration, connections, and running your first migration.
License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file d2-0.8.1.tar.gz.
File metadata
- Download URL: d2-0.8.1.tar.gz
- Upload date:
- Size: 166.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d460d90e018d9a5f3b3132a010748d678be19344cd94fa3557008b238fb5c70
|
|
| MD5 |
7118429f058a18a68e78876cc74b69c9
|
|
| BLAKE2b-256 |
4140a6cc107577015e3031e6435412e605cf51b228c7b30865c2dc33ecb50b35
|
Provenance
The following attestation bundles were made for d2-0.8.1.tar.gz:
Publisher:
release.yml on okanakbulut/d2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
d2-0.8.1.tar.gz -
Subject digest:
5d460d90e018d9a5f3b3132a010748d678be19344cd94fa3557008b238fb5c70 - Sigstore transparency entry: 2193495824
- Sigstore integration time:
-
Permalink:
okanakbulut/d2@a4a3c1733404590ee5cede307d55d1f4a1b725b6 -
Branch / Tag:
refs/tags/v0.8.1 - Owner: https://github.com/okanakbulut
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a4a3c1733404590ee5cede307d55d1f4a1b725b6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file d2-0.8.1-py3-none-any.whl.
File metadata
- Download URL: d2-0.8.1-py3-none-any.whl
- Upload date:
- Size: 42.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a16ada514d0fbdc8a1b3ee0c4fe34cfcd68bfa8c4e90f44d08466ce360d22a02
|
|
| MD5 |
8c0f464a08ce643638410bd9a79460be
|
|
| BLAKE2b-256 |
c37b660c9b222d0c373692ce14b155240912800311da332f04e665fc08c12ecf
|
Provenance
The following attestation bundles were made for d2-0.8.1-py3-none-any.whl:
Publisher:
release.yml on okanakbulut/d2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
d2-0.8.1-py3-none-any.whl -
Subject digest:
a16ada514d0fbdc8a1b3ee0c4fe34cfcd68bfa8c4e90f44d08466ce360d22a02 - Sigstore transparency entry: 2193495847
- Sigstore integration time:
-
Permalink:
okanakbulut/d2@a4a3c1733404590ee5cede307d55d1f4a1b725b6 -
Branch / Tag:
refs/tags/v0.8.1 - Owner: https://github.com/okanakbulut
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a4a3c1733404590ee5cede307d55d1f4a1b725b6 -
Trigger Event:
push
-
Statement type: