Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/routes/docs/products/databases/operators/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2101,11 +2101,11 @@ result = tablesDB.update_row(
'upvotes': Operator.increment(1),
'lastModified': Operator.dateSetNow()
},
transaction_id=tx['$id']
transaction_id=tx.id
)

# Commit the transaction
tablesDB.update_transaction(tx['$id'], 'commit')
tablesDB.update_transaction(tx.id, 'commit')
```
```server-dotnet
using Appwrite;
Expand Down Expand Up @@ -2580,7 +2580,7 @@ tx = tablesDB.create_transaction()

# Stage multiple operations at once using createOperations
tablesDB.create_operations(
transaction_id=tx['$id'],
transaction_id=tx.id,
operations=[
{
'action': 'update',
Expand All @@ -2605,7 +2605,7 @@ tablesDB.create_operations(
)

# Commit the transaction
tablesDB.update_transaction(tx['$id'], 'commit')
tablesDB.update_transaction(tx.id, 'commit')
```
```server-dotnet
using Appwrite;
Expand Down
10 changes: 5 additions & 5 deletions src/routes/docs/products/databases/transactions/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ tablesDB.upsert_row(
table_id = '<TABLE_ID>',
row_id = '<ROW_ID>',
data = { 'name': 'Walter' },
transaction_id = tx['$id']
transaction_id = tx.id
)

# Decrement inside a transaction
Expand All @@ -470,7 +470,7 @@ tablesDB.decrement_row_column(
row_id = '<ROW_ID>',
column = 'credits',
value = 1,
transaction_id = tx['$id']
transaction_id = tx.id
)
```
```server-php
Expand Down Expand Up @@ -668,7 +668,7 @@ await tablesDB.createOperations({
```
```server-python
tablesDB.create_operations(
transaction_id = tx['$id'],
transaction_id = tx.id,
operations = [
{
'action': 'create',
Expand Down Expand Up @@ -1072,13 +1072,13 @@ await tablesDB.updateTransaction({
```server-python
# Commit
tablesDB.update_transaction(
transaction_id = tx['$id'],
transaction_id = tx.id,
commit = True
)

# Roll back
tablesDB.update_transaction(
transaction_id = tx['$id'],
transaction_id = tx.id,
rollback = True
)
```
Expand Down
113 changes: 66 additions & 47 deletions src/routes/docs/quick-starts/python/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,15 @@ Finally, create a file `my_app.py`.
Install the Python Appwrite SDK.

```sh
pip install appwrite==13.6.1
pip install appwrite
```

Or with `uv`:

```sh
uv add appwrite
```

{% /section %}
{% section #step-4 step=4 title="Import Appwrite" %}

Expand Down Expand Up @@ -105,9 +112,18 @@ client.set_key('<YOUR_API_KEY>')
{% /section %}
{% section #step-5 step=5 title="Initialize database" %}

Once the Appwrite Client is initialized, create a function to configure a todo table.
Once the Appwrite Client is initialized, define a Pydantic model for type-safe data access and create a function to configure a todo table.

```py
from pydantic import BaseModel
from typing import Optional

# Define a Pydantic model matching the table schema
class Todo(BaseModel):
title: str
description: Optional[str] = None
isComplete: bool

tablesDB = TablesDB(client)

todoDatabase = None
Expand All @@ -123,30 +139,30 @@ def prepare_database():
)

todoTable = tablesDB.create_table(
database_id=todoDatabase['$id'],
database_id=todoDatabase.id,
table_id=ID.unique(),
name='Todos'
)

tablesDB.create_varchar_column(
database_id=todoDatabase['$id'],
table_id=todoTable['$id'],
database_id=todoDatabase.id,
table_id=todoTable.id,
key='title',
size=255,
required=True
)

tablesDB.create_text_column(
database_id=todoDatabase['$id'],
table_id=todoTable['$id'],
database_id=todoDatabase.id,
table_id=todoTable.id,
key='description',
required=False,
default='This is a test description.'
)

tablesDB.create_boolean_column(
database_id=todoDatabase['$id'],
table_id=todoTable['$id'],
database_id=todoDatabase.id,
table_id=todoTable.id,
key='isComplete',
required=True
)
Expand All @@ -158,42 +174,42 @@ Create a function to add some mock data into your new table.

```py
def seed_database():
testTodo1 = {
'title': "Buy apples",
'description': "At least 2KGs",
'isComplete': True
}

testTodo2 = {
'title': "Wash the apples",
'isComplete': True
}

testTodo3 = {
'title': "Cut the apples",
'description': "Don\'t forget to pack them in a box",
'isComplete': False
}
testTodo1 = Todo(
title="Buy apples",
description="At least 2KGs",
isComplete=True
)

testTodo2 = Todo(
title="Wash the apples",
isComplete=True
)

testTodo3 = Todo(
title="Cut the apples",
description="Don\'t forget to pack them in a box",
isComplete=False
)

tablesDB.create_row(
database_id=todoDatabase['$id'],
table_id=todoTable['$id'],
database_id=todoDatabase.id,
table_id=todoTable.id,
row_id=ID.unique(),
data=testTodo1
data=testTodo1.model_dump()
)

tablesDB.create_row(
database_id=todoDatabase['$id'],
table_id=todoTable['$id'],
database_id=todoDatabase.id,
table_id=todoTable.id,
row_id=ID.unique(),
data=testTodo2
data=testTodo2.model_dump()
)

tablesDB.create_row(
database_id=todoDatabase['$id'],
table_id=todoTable['$id'],
database_id=todoDatabase.id,
table_id=todoTable.id,
row_id=ID.unique(),
data=testTodo3
data=testTodo3.model_dump()
)
```

Expand All @@ -207,43 +223,46 @@ then execute the functions in `_main_`.
from appwrite.query import Query

def get_todos():
# Retrieve rows (default limit is 25)
# Retrieve rows with type-safe access (default limit is 25)
todos = tablesDB.list_rows(
database_id=todoDatabase['$id'],
table_id=todoTable['$id']
database_id=todoDatabase.id,
table_id=todoTable.id,
model_type=Todo
)
print("Todos:")
for todo in todos['rows']:
print(f"Title: {todo['title']}\nDescription: {todo['description']}\nIs Todo Complete: {todo['isComplete']}\n\n")
for todo in todos.rows:
print(f"Title: {todo.data.title}\nDescription: {todo.data.description}\nIs Todo Complete: {todo.data.isComplete}\n\n")

def get_completed_todos():
# Use queries to filter completed todos with pagination
todos = tablesDB.list_rows(
database_id=todoDatabase['$id'],
table_id=todoTable['$id'],
database_id=todoDatabase.id,
table_id=todoTable.id,
model_type=Todo,
queries=[
Query.equal("isComplete", True),
Query.order_desc("$createdAt"),
Query.limit(5)
]
)
print("Completed todos (limited to 5):")
for todo in todos['rows']:
print(f"Title: {todo['title']}\nDescription: {todo['description']}\nIs Todo Complete: {todo['isComplete']}\n\n")
for todo in todos.rows:
print(f"Title: {todo.data.title}\nDescription: {todo.data.description}\nIs Todo Complete: {todo.data.isComplete}\n\n")

def get_incomplete_todos():
# Query for incomplete todos
todos = tablesDB.list_rows(
database_id=todoDatabase['$id'],
table_id=todoTable['$id'],
database_id=todoDatabase.id,
table_id=todoTable.id,
model_type=Todo,
queries=[
Query.equal("isComplete", False),
Query.order_asc("title")
]
)
print("Incomplete todos (ordered by title):")
for todo in todos['rows']:
print(f"Title: {todo['title']}\nDescription: {todo['description']}\nIs Todo Complete: {todo['isComplete']}\n\n")
for todo in todos.rows:
print(f"Title: {todo.data.title}\nDescription: {todo.data.description}\nIs Todo Complete: {todo.data.isComplete}\n\n")

if __name__ == "__main__":
prepare_database()
Expand Down
Loading