Skip to content

Commit 3f0b4ce

Browse files
committed
chore: update Python SDK to 16.0.0
1 parent fa289e0 commit 3f0b4ce

155 files changed

Lines changed: 1264 additions & 1280 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
## 16.0.0
44

55
* 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
67
* Breaking change: Added `pydantic>=2,<3` as a required dependency
78
* Breaking change: Minimum Python version raised from 3.5 to 3.9
89
* Added `AppwriteModel` base class (Pydantic `BaseModel`) for all response models with `from_dict()` and `to_dict()` helpers
910
* 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`
1312
* Updated README with `uv add appwrite` installation example
1413
* Updated all doc examples to use typed response models (e.g., `result: TemplateFunctionList = functions.list_templates(...)`)
1514

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,56 @@ print(user.name) # Access fields as attributes
8484
print(user.to_dict()) # Convert to dictionary if needed
8585
```
8686

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+
class Post(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+
87137
### Error Handling
88138
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.
89139

appwrite/models/activity_event.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Dict, List, Optional, Union
2-
3-
from pydantic import Field
1+
from typing import Any, Dict, List, Optional, Union, cast
2+
from pydantic import Field, PrivateAttr
43

54
from .base_model import AppwriteModel
65

appwrite/models/activity_event_list.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Dict, List, Optional, Union
2-
3-
from pydantic import Field
1+
from typing import Any, Dict, List, Optional, Union, cast
2+
from pydantic import Field, PrivateAttr
43

54
from .base_model import AppwriteModel
65
from .activity_event import ActivityEvent

appwrite/models/algo_argon2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Dict, List, Optional, Union
2-
3-
from pydantic import Field
1+
from typing import Any, Dict, List, Optional, Union, cast
2+
from pydantic import Field, PrivateAttr
43

54
from .base_model import AppwriteModel
65

appwrite/models/algo_bcrypt.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Dict, List, Optional, Union
2-
3-
from pydantic import Field
1+
from typing import Any, Dict, List, Optional, Union, cast
2+
from pydantic import Field, PrivateAttr
43

54
from .base_model import AppwriteModel
65

appwrite/models/algo_md5.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Dict, List, Optional, Union
2-
3-
from pydantic import Field
1+
from typing import Any, Dict, List, Optional, Union, cast
2+
from pydantic import Field, PrivateAttr
43

54
from .base_model import AppwriteModel
65

appwrite/models/algo_phpass.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Dict, List, Optional, Union
2-
3-
from pydantic import Field
1+
from typing import Any, Dict, List, Optional, Union, cast
2+
from pydantic import Field, PrivateAttr
43

54
from .base_model import AppwriteModel
65

appwrite/models/algo_scrypt.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Dict, List, Optional, Union
2-
3-
from pydantic import Field
1+
from typing import Any, Dict, List, Optional, Union, cast
2+
from pydantic import Field, PrivateAttr
43

54
from .base_model import AppwriteModel
65

appwrite/models/algo_scrypt_modified.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Dict, List, Optional, Union
2-
3-
from pydantic import Field
1+
from typing import Any, Dict, List, Optional, Union, cast
2+
from pydantic import Field, PrivateAttr
43

54
from .base_model import AppwriteModel
65

0 commit comments

Comments
 (0)