Skip to main content

Quick Start

This guide will help you get started with dkmio in just a few minutes.

Basic Setup

from dkmio import DynamoDB, PK, SK, Index

db = DynamoDB(region_name="us-east-1")

class Orders(db.Table):
__table_name__ = "orders"
pk = PK("user_id")
sk = SK("order_id")
by_status = Index("gsi-status", pk="status", sk="created_at")

orders = Orders()

Read Operations

Get a single item

order = orders.get(user_id="usr_123", order_id="ord_456")
if order:
print(order["status"])

Query with conditions

# Basic query — returns all orders for a user
results = orders.query(user_id="usr_123")

# Chain conditions
results = (
orders.query(user_id="usr_123")
.where(gte="ord_100") # sort key condition
.filter(total__gt=100) # filter condition
.select("total", "status") # projection
.limit(20) # max items per page
.scan_forward(False) # descending order
)

# Iterate — auto-executes on first access
for order in results:
print(order["total"])

Write Operations

Put an item

orders.put(user_id="usr_123", order_id="ord_789", status="NEW", total=250)

Update an item

orders.update(
user_id="usr_123", order_id="ord_789",
set={"status": "SHIPPED", "shipped_at": "2025-02-24"},
)

Delete an item

orders.delete(user_id="usr_123", order_id="ord_789")

What's Next?