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.9.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.9.0
File Size Uploaded
d2-0.9.0.tar.gz 187.2 kB Details

Built distribution (wheel)

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

Total release size: 230.0 kB

Release files / d2-0.9.0.tar.gz

Download URL d2-0.9.0.tar.gz
Size 187.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b2818c7c99dbd7b9a405575c0d6ed7319004397309b27abc1700e25a8f94530e
BLAKE2b-256 checksum
How to use checksums
e0842e0f7cc5af0eef556b515b4ce2e9a5102702daa2e8b117970613915b811f
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 7, 2026.

Transparency log

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

Download URL d2-0.9.0-py3-none-any.whl
Size 42.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0921f8136a15a13446aa9ceb2029aac638e82c12654846cd7ca71254d003960
BLAKE2b-256 checksum
How to use checksums
2cebea19301b3a040d119ab848d712a105593ee92298f75fc03bd9f200d0a7db
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 7, 2026.

Transparency log

Release history Release notifications | RSS feed

0.10.0

2 release files

This release

0.9.0 This release

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