Skip to main content

d2

Coverage

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

MIT

Release files for d2 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for d2 0.10.0
File Size Uploaded
d2-0.10.0.tar.gz 190.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for d2 0.10.0
File Interpreter ABI Platform
d2-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 235.4 kB

Release files / d2-0.10.0.tar.gz

Download URL d2-0.10.0.tar.gz
Size 190.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c40a43481f048be84884a9f5b66d699359652f091d3c04dc29df148af2ab4a3d
BLAKE2b-256 checksum
How to use checksums
9222a3e9432c8deda8ef991f3ed59b1de7ab48c5dd53a12b30705d9675968b4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Sep 22, 2026.

Transparency log

Release files / d2-0.10.0-py3-none-any.whl

Download URL d2-0.10.0-py3-none-any.whl
Size 45.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e36f7b8f224a3fa831a9b2ab1fda95b8e6d63af4a503d8f49b1c6953ba415923
BLAKE2b-256 checksum
How to use checksums
6eb0505fa15913b14b0e28a14dd7ebd216a2fb4b61dac8853c656558efa2f17b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page