Metadata-Version: 2.4
Name: d2
Version: 0.8.1
Summary: A Python ORM built around a type-safe query builder, with declarative schemas and integrated migrations
Project-URL: Homepage, https://okanakbulut.github.io/d2/
Project-URL: Documentation, https://okanakbulut.github.io/d2/
Project-URL: Repository, https://github.com/okanakbulut/d2
Project-URL: Issues, https://github.com/okanakbulut/d2/issues
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.14
Requires-Dist: asyncpg>=0.31.0
Requires-Dist: msgspec>=0.21.1
Requires-Dist: pypika>=0.51.1
Description-Content-Type: text/markdown

# 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](https://github.com/MagicStack/asyncpg) today, with results deserialised via [msgspec](https://github.com/jcrist/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.

```sh
pip install d2
```

## Quick example

```python
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](docs/getting-started.md) for configuration, connections, and running your first migration.

## License

[MIT](LICENSE)
