Skip to content

Commit 98d20c3

Browse files
authored
Merge pull request #136 from appwrite/dev
feat: Python SDK update for version 16.0.0rc1
2 parents 5b93ea7 + b1b0556 commit 98d20c3

File tree

533 files changed

+14096
-3559
lines changed

Some content is hidden

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

533 files changed

+14096
-3559
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Change Log
22

3+
## 16.0.0rc1
4+
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
7+
* Breaking change: Added `pydantic>=2,<3` as a required dependency
8+
* Breaking change: Minimum Python version raised from 3.5 to 3.9
9+
* Added `AppwriteModel` base class (Pydantic `BaseModel`) for all response models with `from_dict()` and `to_dict()` helpers
10+
* Added 130+ typed model classes under `appwrite/models/` (e.g., `Database`, `Collection`, `Document`, `User`, `Session`, `File`, `Bucket`, etc.)
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`
12+
* Updated README with `uv add appwrite` installation example
13+
* Updated all doc examples to use typed response models (e.g., `result: TemplateFunctionList = functions.list_templates(...)`)
14+
315
## 15.3.0
416

517
* Added get_console_pausing health endpoint

README.md

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ To install via [PyPI](https://pypi.org/):
2020
pip install appwrite
2121
```
2222

23+
Or with `uv`:
24+
25+
```bash
26+
uv add appwrite
27+
```
28+
2329

2430
## Getting Started
2531

@@ -43,10 +49,16 @@ client = Client()
4349
### Make Your First Request
4450
Once your SDK object is set, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section.
4551

52+
All service methods return typed Pydantic models, so you can access response fields as attributes:
53+
4654
```python
4755
users = Users(client)
4856

49-
result = users.create(ID.unique(), email = "email@example.com", phone = "+123456789", password = "password", name = "Walter O'Brien")
57+
user = users.create(ID.unique(), email = "email@example.com", phone = "+123456789", password = "password", name = "Walter O'Brien")
58+
59+
print(user.name) # "Walter O'Brien"
60+
print(user.email) # "email@example.com"
61+
print(user.id) # The generated user ID
5062
```
5163

5264
### Full Example
@@ -66,7 +78,60 @@ client = Client()
6678

6779
users = Users(client)
6880

69-
result = users.create(ID.unique(), email = "email@example.com", phone = "+123456789", password = "password", name = "Walter O'Brien")
81+
user = users.create(ID.unique(), email = "email@example.com", phone = "+123456789", password = "password", name = "Walter O'Brien")
82+
83+
print(user.name) # Access fields as attributes
84+
print(user.to_dict()) # Convert to dictionary if needed
85+
```
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+
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}")
70135
```
71136

72137
### Error Handling
@@ -75,7 +140,8 @@ The Appwrite Python SDK raises `AppwriteException` object with `message`, `code`
75140
```python
76141
users = Users(client)
77142
try:
78-
result = users.create(ID.unique(), email = "email@example.com", phone = "+123456789", password = "password", name = "Walter O'Brien")
143+
user = users.create(ID.unique(), email = "email@example.com", phone = "+123456789", password = "password", name = "Walter O'Brien")
144+
print(user.name)
79145
except AppwriteException as e:
80146
print(e.message)
81147
```

appwrite/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def __init__(self):
1515
self._endpoint = 'https://cloud.appwrite.io/v1'
1616
self._global_headers = {
1717
'content-type': '',
18-
'user-agent' : f'AppwritePythonSDK/15.3.0 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})',
18+
'user-agent' : f'AppwritePythonSDK/16.0.0rc1 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})',
1919
'x-sdk-name': 'Python',
2020
'x-sdk-platform': 'server',
2121
'x-sdk-language': 'python',
22-
'x-sdk-version': '15.3.0',
22+
'x-sdk-version': '16.0.0rc1',
2323
'X-Appwrite-Response-Format' : '1.8.0',
2424
}
2525

appwrite/encoders/value_class_encoder.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from ..models.base_model import AppwriteModel
23
from ..enums.authenticator_type import AuthenticatorType
34
from ..enums.authentication_factor import AuthenticationFactor
45
from ..enums.o_auth_provider import OAuthProvider
@@ -43,6 +44,9 @@
4344

4445
class ValueClassEncoder(json.JSONEncoder):
4546
def default(self, o):
47+
if isinstance(o, AppwriteModel):
48+
return o.to_dict()
49+
4650
if isinstance(o, AuthenticatorType):
4751
return o.value
4852

@@ -166,4 +170,4 @@ def default(self, o):
166170
if isinstance(o, MessageStatus):
167171
return o.value
168172

169-
return super().default(o)
173+
return super().default(o)

0 commit comments

Comments
 (0)