Skip to main content

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

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

d2-0.8.1.tar.gz (166.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

d2-0.8.1-py3-none-any.whl (42.7 kB view details)

Uploaded Python 3

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

Hashes for d2-0.8.1.tar.gz
Algorithm Hash digest
SHA256 5d460d90e018d9a5f3b3132a010748d678be19344cd94fa3557008b238fb5c70
MD5 7118429f058a18a68e78876cc74b69c9
BLAKE2b-256 4140a6cc107577015e3031e6435412e605cf51b228c7b30865c2dc33ecb50b35

See more details on using hashes here.

Provenance

The following attestation bundles were made for d2-0.8.1.tar.gz:

Publisher: release.yml on okanakbulut/d2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for d2-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a16ada514d0fbdc8a1b3ee0c4fe34cfcd68bfa8c4e90f44d08466ce360d22a02
MD5 8c0f464a08ce643638410bd9a79460be
BLAKE2b-256 c37b660c9b222d0c373692ce14b155240912800311da332f04e665fc08c12ecf

See more details on using hashes here.

Provenance

The following attestation bundles were made for d2-0.8.1-py3-none-any.whl:

Publisher: release.yml on okanakbulut/d2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page