Skip to content
Closed
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
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Virtual environments
.venv/
venv/
env/

# Python bytecode
__pycache__/
*.py[cod]

# Packaging / build artifacts
build/
dist/
*.egg-info/
.eggs/

# Test and tooling caches
.pytest_cache/
.mypy_cache/
.ruff_cache/
.coverage
htmlcov/

# Editor and OS files
.idea/
.vscode/
.DS_Store
85 changes: 54 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Appwrite is an open-source backend as a service server that abstracts and simpli

## Installation

Requires Python 3.9 or later. Install the [`appwrite`](https://pypi.org/project/appwrite/) package from PyPI:
Requires Python 3.11 or later. Install the [`appwrite`](https://pypi.org/project/appwrite/) package from PyPI:

```bash
pip install appwrite
Expand All @@ -27,6 +27,8 @@ uv add appwrite

## Getting started

Every API call is asynchronous, so every service method returns a coroutine you `await`.

### Initialize the client

Create a client with your Appwrite endpoint, project ID and an [API key](https://appwrite.io/docs/partners/project/api-keys). Find the endpoint and project ID in your project's **Settings** page, and create an API key with only the scopes you need under **API keys** in the project sidebar.
Expand All @@ -44,24 +46,31 @@ API keys grant server-level access to your project. Keep them out of client-side

### Make a request

Create a service object with the client and call any of its methods. Every method returns a typed Pydantic model, so response fields are available as attributes.
Create a service object with the client and await any of its methods. Every method returns a typed Pydantic model, so response fields are available as attributes.

```python
import asyncio

from appwrite.id import ID
from appwrite.services.users import Users

users = Users(client)

user = users.create(
user_id=ID.unique(),
email='email@example.com',
password='password',
name="Walter O'Brien",
)
async def main():
users = Users(client)

user = await users.create(
user_id=ID.unique(),
email='email@example.com',
password='password',
name="Walter O'Brien",
)

print(user.id)
print(user.name)
print(user.to_dict())

print(user.id)
print(user.name)
print(user.to_dict())

asyncio.run(main())
```

See the [API reference](https://appwrite.io/docs/references/cloud/server-python/users) for every service and method.
Expand All @@ -86,28 +95,29 @@ class Post(BaseModel):
excerpt: Optional[str] = None


tables_db = TablesDB(client)
async def main():
Comment thread
Xharry01X marked this conversation as resolved.
tables_db = TablesDB(client)

row = tables_db.create_row(
database_id='<DATABASE_ID>',
table_id='<TABLE_ID>',
row_id=ID.unique(),
data={'title': 'Hello, world', 'published': True},
model_type=Post,
)
row = await tables_db.create_row(
database_id='<DATABASE_ID>',
table_id='<TABLE_ID>',
row_id=ID.unique(),
data={'title': 'Hello, world', 'published': True},
model_type=Post,
)

print(row.id)
print(row.data.title)
print(row.id)
print(row.data.title)

result = tables_db.list_rows(
database_id='<DATABASE_ID>',
table_id='<TABLE_ID>',
queries=[Query.equal('published', True), Query.limit(25)],
model_type=Post,
)
result = await tables_db.list_rows(
database_id='<DATABASE_ID>',
table_id='<TABLE_ID>',
queries=[Query.equal('published', True), Query.limit(25)],
model_type=Post,
)

for row in result.rows:
print(row.data.title)
for row in result.rows:
print(row.data.title)
```

### Handle errors
Expand All @@ -118,11 +128,24 @@ Failed requests raise `AppwriteException`, which carries `message`, `code`, `typ
from appwrite.exception import AppwriteException

try:
user = users.get(user_id='<USER_ID>')
user = await users.get(user_id='<USER_ID>')
except AppwriteException as error:
print(error.code, error.type, error.message)
```

### Close the client

The client keeps a pooled HTTP connection open. Close it when you are done, or use it as an async context manager.

```python
await client.aclose()
```

```python
async with Client() as client:
...
```

### Self-hosted Appwrite

Point the client at your own instance instead of Appwrite Cloud. Call `set_self_signed()` only in development, when the server uses a self-signed TLS certificate.
Expand Down
Loading
Loading