From 619eadf6671881ded5b655e01321604a95ca91a4 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 25 Nov 2026 14:56:35 +0000 Subject: [PATCH 1/2] feat: add Bird messaging providers for version 28.1.0 --- CHANGELOG.md | 4 + appwrite/client.py | 4 +- appwrite/services/messaging.py | 276 ++++++++++++++++++ .../messaging/create-bird-email-provider.md | 25 ++ .../messaging/create-bird-sms-provider.md | 22 ++ .../messaging/update-bird-email-provider.md | 25 ++ .../messaging/update-bird-sms-provider.md | 22 ++ pyproject.toml | 2 +- setup.py | 4 +- test/services/test_messaging.py | 190 ++++++++++++ 10 files changed, 569 insertions(+), 5 deletions(-) create mode 100644 docs/examples/messaging/create-bird-email-provider.md create mode 100644 docs/examples/messaging/create-bird-sms-provider.md create mode 100644 docs/examples/messaging/update-bird-email-provider.md create mode 100644 docs/examples/messaging/update-bird-sms-provider.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d88f2ff..5bb6f140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 28.1.0 + +* Added: `messaging.create_bird_email_provider`, `update_bird_email_provider`, `create_bird_sms_provider` and `update_bird_sms_provider` for the Bird email and SMS providers + ## 28.0.0 * Breaking: `email_enabled` moved after the new provider params in positional `functions.update` calls diff --git a/appwrite/client.py b/appwrite/client.py index c1eab5b0..b17316d4 100644 --- a/appwrite/client.py +++ b/appwrite/client.py @@ -20,11 +20,11 @@ def __init__(self): self._endpoint = 'https://cloud.appwrite.io/v1' self._global_headers = { 'content-type': '', - 'user-agent': f'AppwritePythonSDK/28.0.0 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})', + 'user-agent': f'AppwritePythonSDK/28.1.0 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})', 'x-sdk-name': 'Python', 'x-sdk-platform': 'server', 'x-sdk-language': 'python', - 'x-sdk-version': '28.0.0', + 'x-sdk-version': '28.1.0', 'X-Appwrite-Response-Format': '2.7.2', } self._config = {} diff --git a/appwrite/services/messaging.py b/appwrite/services/messaging.py index cab499ba..8cff263c 100644 --- a/appwrite/services/messaging.py +++ b/appwrite/services/messaging.py @@ -1165,6 +1165,282 @@ def update_appwrite_provider( return self._parse_response(response, model=Provider) + def create_bird_email_provider( + self, + provider_id: str, + name: str, + api_key: Optional[str] = None, + from_name: Optional[str] = None, + from_email: Optional[str] = None, + reply_to_name: Optional[str] = None, + reply_to_email: Optional[str] = None, + enabled: Optional[bool] = None, + ) -> Provider: + """ + Create a new Bird email provider. It sends email through Bird's email API with a workspace API key that holds the `emails:write` scope. + + Parameters + ---------- + provider_id : str + Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + name : str + Provider name. + api_key : Optional[str] + Bird workspace API key. + from_name : Optional[str] + Sender Name. + from_email : Optional[str] + Sender email address. Its domain must be verified in the Bird workspace. + reply_to_name : Optional[str] + Name set in the reply to field for the mail. Default value is sender name. + reply_to_email : Optional[str] + Email set in the reply to field for the mail. Default value is sender email. + enabled : Optional[bool] + Set as enabled. + Returns + ------- + Provider + API response as a typed Pydantic model + + Raises + ------ + AppwriteException + If API request fails + """ + + api_path = '/messaging/providers/bird-email' + api_params = {} + if provider_id is None: + raise AppwriteException('Missing required parameter: "provider_id"') + if name is None: + raise AppwriteException('Missing required parameter: "name"') + api_params['providerId'] = self._normalize_value(provider_id) + api_params['name'] = self._normalize_value(name) + if api_key is not None: + api_params['apiKey'] = self._normalize_value(api_key) + if from_name is not None: + api_params['fromName'] = self._normalize_value(from_name) + if from_email is not None: + api_params['fromEmail'] = self._normalize_value(from_email) + if reply_to_name is not None: + api_params['replyToName'] = self._normalize_value(reply_to_name) + if reply_to_email is not None: + api_params['replyToEmail'] = self._normalize_value(reply_to_email) + if enabled is not None: + api_params['enabled'] = self._normalize_value(enabled) + + response = self.client.call( + 'post', + api_path, + { + 'X-Appwrite-Project': self.client.get_config('project'), + 'content-type': 'application/json', + 'accept': 'application/json', + }, + api_params, + ) + + return self._parse_response(response, model=Provider) + + def update_bird_email_provider( + self, + provider_id: str, + name: Optional[str] = None, + enabled: Optional[bool] = None, + api_key: Optional[str] = None, + from_name: Optional[str] = None, + from_email: Optional[str] = None, + reply_to_name: Optional[str] = None, + reply_to_email: Optional[str] = None, + ) -> Provider: + """ + Update a Bird email provider by its unique ID. + + Parameters + ---------- + provider_id : str + Provider ID. + name : Optional[str] + Provider name. + enabled : Optional[bool] + Set as enabled. + api_key : Optional[str] + Bird workspace API key. + from_name : Optional[str] + Sender Name. + from_email : Optional[str] + Sender email address. Its domain must be verified in the Bird workspace. + reply_to_name : Optional[str] + Name set in the Reply To field for the mail. Default value is Sender Name. + reply_to_email : Optional[str] + Email set in the Reply To field for the mail. Default value is Sender Email. + Returns + ------- + Provider + API response as a typed Pydantic model + + Raises + ------ + AppwriteException + If API request fails + """ + + api_path = '/messaging/providers/bird-email/{providerId}' + api_params = {} + if provider_id is None or provider_id == '': + raise AppwriteException('Missing required parameter: "provider_id"') + api_path = api_path.replace('{providerId}', self._encode_path(provider_id)) + if name is not None: + api_params['name'] = self._normalize_value(name) + if enabled is not None: + api_params['enabled'] = self._normalize_value(enabled) + if api_key is not None: + api_params['apiKey'] = self._normalize_value(api_key) + if from_name is not None: + api_params['fromName'] = self._normalize_value(from_name) + if from_email is not None: + api_params['fromEmail'] = self._normalize_value(from_email) + if reply_to_name is not None: + api_params['replyToName'] = self._normalize_value(reply_to_name) + if reply_to_email is not None: + api_params['replyToEmail'] = self._normalize_value(reply_to_email) + + response = self.client.call( + 'patch', + api_path, + { + 'X-Appwrite-Project': self.client.get_config('project'), + 'content-type': 'application/json', + 'accept': 'application/json', + }, + api_params, + ) + + return self._parse_response(response, model=Provider) + + def create_bird_sms_provider( + self, + provider_id: str, + name: str, + xfrom: Optional[str] = None, + api_key: Optional[str] = None, + enabled: Optional[bool] = None, + ) -> Provider: + """ + Create a new Bird SMS provider. It sends SMS through Bird with a workspace API key that holds the `sms:write` scope. + + Parameters + ---------- + provider_id : str + Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + name : str + Provider name. + xfrom : Optional[str] + Sender phone number or alphanumeric sender ID. Format phone numbers with a leading '+' and a country code, e.g., +16175551212. + api_key : Optional[str] + Bird workspace API key. + enabled : Optional[bool] + Set as enabled. + Returns + ------- + Provider + API response as a typed Pydantic model + + Raises + ------ + AppwriteException + If API request fails + """ + + api_path = '/messaging/providers/bird-sms' + api_params = {} + if provider_id is None: + raise AppwriteException('Missing required parameter: "provider_id"') + if name is None: + raise AppwriteException('Missing required parameter: "name"') + api_params['providerId'] = self._normalize_value(provider_id) + api_params['name'] = self._normalize_value(name) + if xfrom is not None: + api_params['from'] = self._normalize_value(xfrom) + if api_key is not None: + api_params['apiKey'] = self._normalize_value(api_key) + if enabled is not None: + api_params['enabled'] = self._normalize_value(enabled) + + response = self.client.call( + 'post', + api_path, + { + 'X-Appwrite-Project': self.client.get_config('project'), + 'content-type': 'application/json', + 'accept': 'application/json', + }, + api_params, + ) + + return self._parse_response(response, model=Provider) + + def update_bird_sms_provider( + self, + provider_id: str, + name: Optional[str] = None, + enabled: Optional[bool] = None, + api_key: Optional[str] = None, + xfrom: Optional[str] = None, + ) -> Provider: + """ + Update a Bird SMS provider by its unique ID. + + Parameters + ---------- + provider_id : str + Provider ID. + name : Optional[str] + Provider name. + enabled : Optional[bool] + Set as enabled. + api_key : Optional[str] + Bird workspace API key. + xfrom : Optional[str] + Sender phone number or alphanumeric sender ID. Format phone numbers with a leading '+' and a country code, e.g., +16175551212. + Returns + ------- + Provider + API response as a typed Pydantic model + + Raises + ------ + AppwriteException + If API request fails + """ + + api_path = '/messaging/providers/bird-sms/{providerId}' + api_params = {} + if provider_id is None or provider_id == '': + raise AppwriteException('Missing required parameter: "provider_id"') + api_path = api_path.replace('{providerId}', self._encode_path(provider_id)) + if name is not None: + api_params['name'] = self._normalize_value(name) + if enabled is not None: + api_params['enabled'] = self._normalize_value(enabled) + if api_key is not None: + api_params['apiKey'] = self._normalize_value(api_key) + if xfrom is not None: + api_params['from'] = self._normalize_value(xfrom) + + response = self.client.call( + 'patch', + api_path, + { + 'X-Appwrite-Project': self.client.get_config('project'), + 'content-type': 'application/json', + 'accept': 'application/json', + }, + api_params, + ) + + return self._parse_response(response, model=Provider) + def create_fcm_provider( self, provider_id: str, diff --git a/docs/examples/messaging/create-bird-email-provider.md b/docs/examples/messaging/create-bird-email-provider.md new file mode 100644 index 00000000..b9abca53 --- /dev/null +++ b/docs/examples/messaging/create-bird-email-provider.md @@ -0,0 +1,25 @@ +```python +from appwrite.client import Client +from appwrite.services.messaging import Messaging +from appwrite.models import Provider + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your secret API key + +messaging = Messaging(client) + +result: Provider = messaging.create_bird_email_provider( + provider_id = '', + name = '', + api_key = '', # optional + from_name = '', # optional + from_email = 'email@example.com', # optional + reply_to_name = '', # optional + reply_to_email = 'email@example.com', # optional + enabled = False # optional +) + +print(result.model_dump()) +``` diff --git a/docs/examples/messaging/create-bird-sms-provider.md b/docs/examples/messaging/create-bird-sms-provider.md new file mode 100644 index 00000000..9db16306 --- /dev/null +++ b/docs/examples/messaging/create-bird-sms-provider.md @@ -0,0 +1,22 @@ +```python +from appwrite.client import Client +from appwrite.services.messaging import Messaging +from appwrite.models import Provider + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your secret API key + +messaging = Messaging(client) + +result: Provider = messaging.create_bird_sms_provider( + provider_id = '', + name = '', + from = '', # optional + api_key = '', # optional + enabled = False # optional +) + +print(result.model_dump()) +``` diff --git a/docs/examples/messaging/update-bird-email-provider.md b/docs/examples/messaging/update-bird-email-provider.md new file mode 100644 index 00000000..3dfe93c2 --- /dev/null +++ b/docs/examples/messaging/update-bird-email-provider.md @@ -0,0 +1,25 @@ +```python +from appwrite.client import Client +from appwrite.services.messaging import Messaging +from appwrite.models import Provider + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your secret API key + +messaging = Messaging(client) + +result: Provider = messaging.update_bird_email_provider( + provider_id = '', + name = '', # optional + enabled = False, # optional + api_key = '', # optional + from_name = '', # optional + from_email = 'email@example.com', # optional + reply_to_name = '', # optional + reply_to_email = 'email@example.com' # optional +) + +print(result.model_dump()) +``` diff --git a/docs/examples/messaging/update-bird-sms-provider.md b/docs/examples/messaging/update-bird-sms-provider.md new file mode 100644 index 00000000..efd545ec --- /dev/null +++ b/docs/examples/messaging/update-bird-sms-provider.md @@ -0,0 +1,22 @@ +```python +from appwrite.client import Client +from appwrite.services.messaging import Messaging +from appwrite.models import Provider + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your secret API key + +messaging = Messaging(client) + +result: Provider = messaging.update_bird_sms_provider( + provider_id = '', + name = '', # optional + enabled = False, # optional + api_key = '', # optional + from = '' # optional +) + +print(result.model_dump()) +``` diff --git a/pyproject.toml b/pyproject.toml index 15b94de4..cd83769e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "appwrite" -version = "28.0.0" +version = "28.1.0" description = "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API" readme = "README.md" requires-python = ">=3.10" diff --git a/setup.py b/setup.py index 5eee618a..79f098c9 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name='appwrite', packages=setuptools.find_packages(), - version='28.0.0', + version='28.1.0', license='BSD-3-Clause', description='Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API', long_description=long_description, @@ -18,7 +18,7 @@ maintainer='Appwrite Team', maintainer_email='team@appwrite.io', url='https://appwrite.io/support', - download_url='https://github.com/appwrite/sdk-for-python/archive/28.0.0.tar.gz', + download_url='https://github.com/appwrite/sdk-for-python/archive/28.1.0.tar.gz', install_requires=[ 'requests>=2.34.2,<3', 'urllib3>=2.8.0,<3', diff --git a/test/services/test_messaging.py b/test/services/test_messaging.py index 0c3cf54c..73f0bb99 100644 --- a/test/services/test_messaging.py +++ b/test/services/test_messaging.py @@ -953,6 +953,196 @@ def test_update_appwrite_provider(self, m): ) self.assertEqual(response.to_dict(), data) + @requests_mock.Mocker() + def test_create_bird_email_provider(self, m): + data = { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": True, + "type": "sms", + "credentials": {}, + } + headers = {'Content-Type': 'application/json'} + m.request( + 'POST', + requests_mock.ANY, + text=json.dumps(data), + headers=headers, + ) + response = self.messaging.create_bird_email_provider( + '', + '', + api_key='', + from_name='', + from_email='email@example.com', + reply_to_name='', + reply_to_email='email@example.com', + enabled=False, + ) + request = m.last_request + url = urlsplit(request.url) + self.assertEqual( + unquote(url.path), + '/v1/messaging/providers/bird-email', + ) + sent = json.loads(request.body or '{}') + self.assertEqual( + sent, + { + 'providerId': '', + 'name': '', + 'apiKey': '', + 'fromName': '', + 'fromEmail': 'email@example.com', + 'replyToName': '', + 'replyToEmail': 'email@example.com', + 'enabled': False, + }, + ) + self.assertEqual(response.to_dict(), data) + + @requests_mock.Mocker() + def test_update_bird_email_provider(self, m): + data = { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": True, + "type": "sms", + "credentials": {}, + } + headers = {'Content-Type': 'application/json'} + m.request( + 'PATCH', + requests_mock.ANY, + text=json.dumps(data), + headers=headers, + ) + response = self.messaging.update_bird_email_provider( + '', + name='', + enabled=False, + api_key='', + from_name='', + from_email='email@example.com', + reply_to_name='', + reply_to_email='email@example.com', + ) + request = m.last_request + url = urlsplit(request.url) + self.assertEqual( + unquote(url.path), + '/v1/messaging/providers/bird-email/', + ) + sent = json.loads(request.body or '{}') + self.assertEqual( + sent, + { + 'name': '', + 'enabled': False, + 'apiKey': '', + 'fromName': '', + 'fromEmail': 'email@example.com', + 'replyToName': '', + 'replyToEmail': 'email@example.com', + }, + ) + self.assertEqual(response.to_dict(), data) + + @requests_mock.Mocker() + def test_create_bird_sms_provider(self, m): + data = { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": True, + "type": "sms", + "credentials": {}, + } + headers = {'Content-Type': 'application/json'} + m.request( + 'POST', + requests_mock.ANY, + text=json.dumps(data), + headers=headers, + ) + response = self.messaging.create_bird_sms_provider( + '', + '', + xfrom='', + api_key='', + enabled=False, + ) + request = m.last_request + url = urlsplit(request.url) + self.assertEqual( + unquote(url.path), + '/v1/messaging/providers/bird-sms', + ) + sent = json.loads(request.body or '{}') + self.assertEqual( + sent, + { + 'providerId': '', + 'name': '', + 'from': '', + 'apiKey': '', + 'enabled': False, + }, + ) + self.assertEqual(response.to_dict(), data) + + @requests_mock.Mocker() + def test_update_bird_sms_provider(self, m): + data = { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Mailgun", + "provider": "mailgun", + "enabled": True, + "type": "sms", + "credentials": {}, + } + headers = {'Content-Type': 'application/json'} + m.request( + 'PATCH', + requests_mock.ANY, + text=json.dumps(data), + headers=headers, + ) + response = self.messaging.update_bird_sms_provider( + '', + name='', + enabled=False, + api_key='', + xfrom='', + ) + request = m.last_request + url = urlsplit(request.url) + self.assertEqual( + unquote(url.path), + '/v1/messaging/providers/bird-sms/', + ) + sent = json.loads(request.body or '{}') + self.assertEqual( + sent, + { + 'name': '', + 'enabled': False, + 'apiKey': '', + 'from': '', + }, + ) + self.assertEqual(response.to_dict(), data) + @requests_mock.Mocker() def test_create_fcm_provider(self, m): data = { From 0a9682ef84386de118c7df49f703a29d5b646fb2 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 25 Nov 2026 15:17:07 +0000 Subject: [PATCH 2/2] docs: use xfrom in the Bird SMS provider examples --- docs/examples/messaging/create-bird-sms-provider.md | 2 +- docs/examples/messaging/update-bird-sms-provider.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/examples/messaging/create-bird-sms-provider.md b/docs/examples/messaging/create-bird-sms-provider.md index 9db16306..319a88ac 100644 --- a/docs/examples/messaging/create-bird-sms-provider.md +++ b/docs/examples/messaging/create-bird-sms-provider.md @@ -13,7 +13,7 @@ messaging = Messaging(client) result: Provider = messaging.create_bird_sms_provider( provider_id = '', name = '', - from = '', # optional + xfrom = '', # optional api_key = '', # optional enabled = False # optional ) diff --git a/docs/examples/messaging/update-bird-sms-provider.md b/docs/examples/messaging/update-bird-sms-provider.md index efd545ec..abd28bc6 100644 --- a/docs/examples/messaging/update-bird-sms-provider.md +++ b/docs/examples/messaging/update-bird-sms-provider.md @@ -15,7 +15,7 @@ result: Provider = messaging.update_bird_sms_provider( name = '', # optional enabled = False, # optional api_key = '', # optional - from = '' # optional + xfrom = '' # optional ) print(result.model_dump())