Getting started
This guide walks you through installing pydynox and creating your first model. By the end, you'll have a working DynamoDB model with CRUD operations.
Key features
- Install with pip or uv
- Define models with typed attributes
- CRUD operations with simple methods
- Local development with DynamoDB Local
Installation
To verify the installation:
Your first model
Let's create a simple User model. A model is a Python class that represents items in a DynamoDB table.
from pydynox import Model, ModelConfig
from pydynox.attributes import BooleanAttribute, NumberAttribute, StringAttribute
class User(Model):
model_config = ModelConfig(table="users")
pk = StringAttribute(hash_key=True)
sk = StringAttribute(range_key=True)
name = StringAttribute()
age = NumberAttribute(default=0)
active = BooleanAttribute(default=True)
Here's what each part does:
class Meta- Configuration for the model.tableis the DynamoDB table name.pk = StringAttribute(hash_key=True)- The partition key. Every item needs one.sk = StringAttribute(range_key=True)- The sort key. Optional, but useful for complex access patterns.- Other attributes - Regular fields with their types and optional defaults.
Basic operations
Now let's use the model to work with DynamoDB:
from pydynox import Model, ModelConfig
from pydynox.attributes import NumberAttribute, StringAttribute
class User(Model):
model_config = ModelConfig(table="users")
pk = StringAttribute(hash_key=True)
sk = StringAttribute(range_key=True)
name = StringAttribute()
age = NumberAttribute(default=0)
# Create
user = User(pk="USER#123", sk="PROFILE", name="John", age=30)
user.save()
# Read
user = User.get(pk="USER#123", sk="PROFILE")
if user:
print(user.name) # John
# Update - full
user.name = "Jane"
user.save()
# Update - partial
user.update(name="Jane", age=31)
# Delete
user.delete()
Create
Instantiate your model and call save():
Read
Use get() with the key attributes:
Update
Change attributes and save, or use update() for partial updates:
Delete
Call delete() on an instance:
Configuration
The Meta class configures how your model connects to DynamoDB:
class User(Model):
class Meta:
table = "users" # Required - table name
region = "us-east-1" # Optional - AWS region
endpoint_url = None # Optional - for local testing
Local development
For local testing, use DynamoDB Local. It's a downloadable version of DynamoDB that runs on your machine.
Start DynamoDB Local (using Docker):
Then point your model to it:
Tip
DynamoDB Local is great for development and testing. You don't need AWS credentials, and you won't accidentally modify production data.
Next steps
Now that you have the basics working:
- Models - Learn about all attribute types and options
- Batch operations - Work with multiple items efficiently
- Rate limiting - Control throughput to avoid throttling
- Lifecycle hooks - Add validation and logging