Docs
Skip to content

Quick start

Start with Python_

Learn to get started with server integrations with Appwrite Python SDK.

2 min read

Raw

Learn how to setup your first Python project powered by Appwrite.

1. Create project

Head to the Appwrite Console.

If this is your first time using Appwrite, create an account and create your first project.

Create project screen
Create project screen

Then, under Integrate with your server, add an API Key with the following scopes.

Server integrations
Server integrations

Category Required scopesPurpose
Databasedatabases.writeAllows API key to create, update, and delete databases.
tables.writeAllows API key to create, update, and delete tables.
columns.writeAllows API key to create, update, and delete columns.
rows.readAllows API key to read rows.
rows.writeAllows API key to create, update, and delete rows.

Other scopes are optional.

Project settings screen
Project settings screen

2. Create Python project

Create a directory for the project.

Bash
mkdir my_app
cd my_app

After that, create a virtual environment in this directory and activate it.

Bash
# Create a venv
python -m venv .venv
# Active the venv in Unix shell
source .venv/bin/activate
# Or in Powershell
.venv/Scripts/Activate.ps1

Finally, create a file my_app.py.

3. Install Appwrite

Install the Python Appwrite SDK.

Bash
pip install appwrite

Or with uv:

Bash
uv add appwrite

4. Import Appwrite

Find your project ID in the Settings page. Also, click on the View API Keys button to find the API key that was created earlier.

Project settings screen
Project settings screen

Open my_app.py and initialize the Appwrite Client. Replace <PROJECT_ID> with your project ID and <YOUR_API_KEY> with your API key.

Python
from appwrite.client import Client
from appwrite.services.tables_db import TablesDB
from appwrite.id import ID
client = Client()
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1')
client.set_project('<PROJECT_ID>')
client.set_key('<YOUR_API_KEY>')

5. Initialize database

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

Python
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
todoTable = None
def prepare_database():
global todoDatabase
global todoTable
todoDatabase = tablesDB.create(
database_id=ID.unique(),
name='TodosDB'
)
todoTable = tablesDB.create_table(
database_id=todoDatabase.id,
table_id=ID.unique(),
name='Todos'
)
tablesDB.create_varchar_column(
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,
key='description',
required=False,
default='This is a test description.'
)
tablesDB.create_boolean_column(
database_id=todoDatabase.id,
table_id=todoTable.id,
key='isComplete',
required=True
)

6. Add rows

Create a function to add some mock data into your new table.

Python
def seed_database():
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,
row_id=ID.unique(),
data=testTodo1.model_dump()
)
tablesDB.create_row(
database_id=todoDatabase.id,
table_id=todoTable.id,
row_id=ID.unique(),
data=testTodo2.model_dump()
)
tablesDB.create_row(
database_id=todoDatabase.id,
table_id=todoTable.id,
row_id=ID.unique(),
data=testTodo3.model_dump()
)

7. Retrieve rows

Create a function to retrieve the mock todo data, then execute the functions in _main_.

Python
from appwrite.query import Query
def get_todos():
# Retrieve rows with type-safe access (default limit is 25)
todos = tablesDB.list_rows(
database_id=todoDatabase.id,
table_id=todoTable.id,
model_type=Todo
)
print("Todos:")
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,
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.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,
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.data.title}\nDescription: {todo.data.description}\nIs Todo Complete: {todo.data.isComplete}\n\n")
if __name__ == "__main__":
prepare_database()
seed_database()
get_todos()
get_completed_todos()
get_incomplete_todos()

8. All set

Run your project with python my_app.py and view the response in your console.

Was this page helpful?

Share what worked or what we should fix. Once approved, our agents automatically apply suggested updates to the docs.