You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,12 @@
3
3
## 16.0.0
4
4
5
5
* Breaking change: All service methods now return typed Pydantic models instead of `Dict[str, Any]`
6
+
* Breaking change: Models with dynamic fields (e.g., `Row`, `Document`) now store user-defined data in a typed `.data` property instead of direct attribute access
6
7
* Breaking change: Added `pydantic>=2,<3` as a required dependency
7
8
* Breaking change: Minimum Python version raised from 3.5 to 3.9
8
9
* Added `AppwriteModel` base class (Pydantic `BaseModel`) for all response models with `from_dict()` and `to_dict()` helpers
9
10
* Added 130+ typed model classes under `appwrite/models/` (e.g., `Database`, `Collection`, `Document`, `User`, `Session`, `File`, `Bucket`, etc.)
10
-
* Added `ActivityEvent` and `ActivityEventList` models and `Activities` service
11
-
* Added `ValueClassEncoder` support for serializing `AppwriteModel` instances
12
-
* Added `pyproject.toml` for modern Python packaging
11
+
* Added Generic[T] support for models with dynamic fields (e.g., `Row`, `Document`) - pass `model_type=YourModel` to methods like `get_row()` or `list_rows()` for type-safe access to user-defined data via `result.data.field_name`
13
12
* Updated README with `uv add appwrite` installation example
14
13
* Updated all doc examples to use typed response models (e.g., `result: TemplateFunctionList = functions.list_templates(...)`)
Copy file name to clipboardExpand all lines: README.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,6 +84,56 @@ print(user.name) # Access fields as attributes
84
84
print(user.to_dict()) # Convert to dictionary if needed
85
85
```
86
86
87
+
### Type Safety with Models
88
+
89
+
The Appwrite Python SDK provides type safety when working with database rows through generic methods. Methods like `get_row`, `list_rows`, and others accept a `model_type` parameter that allows you to specify your custom Pydantic model for full type safety.
90
+
91
+
```python
92
+
from pydantic import BaseModel
93
+
from datetime import datetime
94
+
from typing import Optional
95
+
from appwrite.client import Client
96
+
from appwrite.services.tables_db import TablesDB
97
+
98
+
# Define your custom model matching your table schema
99
+
classPost(BaseModel):
100
+
postId: int
101
+
authorId: int
102
+
title: str
103
+
content: str
104
+
createdAt: datetime
105
+
updatedAt: datetime
106
+
isPublished: bool
107
+
excerpt: Optional[str] =None
108
+
109
+
client = Client()
110
+
# ... configure your client ...
111
+
112
+
tables_db = TablesDB(client)
113
+
114
+
# Fetch a single row with type safety
115
+
row = tables_db.get_row(
116
+
database_id="your-database-id",
117
+
table_id="your-table-id",
118
+
row_id="your-row-id",
119
+
model_type=Post # Pass your custom model type
120
+
)
121
+
122
+
print(row.data.title) # Fully typed - IDE autocomplete works
123
+
print(row.data.postId) # int type, not Any
124
+
print(row.data.createdAt) # datetime type
125
+
126
+
# Fetch multiple rows with type safety
127
+
result = tables_db.list_rows(
128
+
database_id="your-database-id",
129
+
table_id="your-table-id",
130
+
model_type=Post
131
+
)
132
+
133
+
for row in result.rows:
134
+
print(f"{row.data.title} by {row.data.authorId}")
135
+
```
136
+
87
137
### Error Handling
88
138
The Appwrite Python SDK raises `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example.
0 commit comments