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
14 changes: 7 additions & 7 deletions postmark/clients/account_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import sys
import uuid
from typing import Any, Dict, List, Optional, Union
from typing import Any

import httpx
from tenacity import (
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(
account_token: str,
retries: int = 3,
timeout: float = 30.0,
base_url: Optional[str] = None,
base_url: str | None = None,
):
"""
Initialize the Postmark Account Client.
Expand Down Expand Up @@ -187,28 +187,28 @@ async def request(self, method: str, endpoint: str, **kwargs) -> httpx.Response:
raise AssertionError("The Postmark API is unreachable.")

async def get(
self, endpoint: str, params: Optional[Dict[str, Any]] = None
self, endpoint: str, params: dict[str, Any] | None = None
) -> httpx.Response:
return await self.request("GET", endpoint, params=params)

async def post(
self,
endpoint: str,
json: Union[Dict[str, Any], List[Dict[str, Any]], None] = None,
json: dict[str, Any] | list[dict[str, Any]] | None = None,
) -> httpx.Response:
return await self.request("POST", endpoint, json=json)

async def put(
self, endpoint: str, json: Optional[Dict[str, Any]] = None
self, endpoint: str, json: dict[str, Any] | None = None
) -> httpx.Response:
return await self.request("PUT", endpoint, json=json)

async def patch(
self, endpoint: str, json: Optional[Dict[str, Any]] = None
self, endpoint: str, json: dict[str, Any] | None = None
) -> httpx.Response:
return await self.request("PATCH", endpoint, json=json)

async def delete(
self, endpoint: str, params: Optional[Dict[str, Any]] = None
self, endpoint: str, params: dict[str, Any] | None = None
) -> httpx.Response:
return await self.request("DELETE", endpoint, params=params)
14 changes: 7 additions & 7 deletions postmark/clients/server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import sys
import uuid
from typing import Any, Dict, List, Optional, Union
from typing import Any

import httpx
from tenacity import (
Expand Down Expand Up @@ -45,7 +45,7 @@ def __init__(
server_token: str,
retries: int = 3,
timeout: float = 5,
base_url: Optional[str] = None,
base_url: str | None = None,
):
"""
Initialize the Postmark Server Client.
Expand Down Expand Up @@ -202,28 +202,28 @@ async def request(self, method: str, endpoint: str, **kwargs) -> httpx.Response:
raise AssertionError("The Postmark API is unreachable.")

async def get(
self, endpoint: str, params: Optional[Dict[str, Any]] = None
self, endpoint: str, params: dict[str, Any] | None = None
) -> httpx.Response:
return await self.request("GET", endpoint, params=params)

async def post(
self,
endpoint: str,
json: Union[Dict[str, Any], List[Dict[str, Any]], None] = None,
json: dict[str, Any] | list[dict[str, Any]] | None = None,
) -> httpx.Response:
return await self.request("POST", endpoint, json=json)

async def put(
self, endpoint: str, json: Optional[Dict[str, Any]] = None
self, endpoint: str, json: dict[str, Any] | None = None
) -> httpx.Response:
return await self.request("PUT", endpoint, json=json)

async def patch(
self, endpoint: str, json: Optional[Dict[str, Any]] = None
self, endpoint: str, json: dict[str, Any] | None = None
) -> httpx.Response:
return await self.request("PATCH", endpoint, json=json)

async def delete(
self, endpoint: str, params: Optional[Dict[str, Any]] = None
self, endpoint: str, params: dict[str, Any] | None = None
) -> httpx.Response:
return await self.request("DELETE", endpoint, params=params)
10 changes: 5 additions & 5 deletions postmark/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Postmark API exceptions."""

import re
from typing import Any, Optional
from typing import Any


class PostmarkException(Exception):
Expand All @@ -10,8 +10,8 @@ class PostmarkException(Exception):
def __init__(
self,
message: str,
error_code: Optional[int] = None,
http_status: Optional[int] = None,
error_code: int | None = None,
http_status: int | None = None,
):
super().__init__(message)
self.error_code = error_code
Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(
message: str,
error_code: int,
http_status: int,
request_id: Optional[str] = None,
request_id: str | None = None,
):
super().__init__(message, error_code, http_status)
self.request_id = request_id
Expand All @@ -75,7 +75,7 @@ def __init__(
message: str,
error_code: int,
http_status: int,
request_id: Optional[str] = None,
request_id: str | None = None,
):
super().__init__(message, error_code, http_status, request_id)
match = re.search(r"Found inactive addresses: ([^.]+)", message)
Expand Down
34 changes: 17 additions & 17 deletions postmark/models/bounces/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from collections.abc import AsyncGenerator
from datetime import datetime
from typing import AsyncGenerator, Optional

from postmark.models.page import Page
from postmark.utils.pagination import paginate
Expand Down Expand Up @@ -33,14 +33,14 @@ async def list(
self,
count: int = 100,
offset: int = 0,
type: Optional[BounceType] = None,
inactive: Optional[bool] = None,
email_filter: Optional[str] = None,
tag: Optional[str] = None,
message_id: Optional[str] = None,
from_date: Optional[datetime] = None,
to_date: Optional[datetime] = None,
message_stream: Optional[str] = None,
type: BounceType | None = None,
inactive: bool | None = None,
email_filter: str | None = None,
tag: str | None = None,
message_id: str | None = None,
from_date: datetime | None = None,
to_date: datetime | None = None,
message_stream: str | None = None,
) -> Page[Bounce]:
"""
List bounces for the server.
Expand Down Expand Up @@ -90,14 +90,14 @@ async def stream(
self,
batch_size: int = 500,
max_bounces: int = 1000,
type: Optional[BounceType] = None,
inactive: Optional[bool] = None,
email_filter: Optional[str] = None,
tag: Optional[str] = None,
message_id: Optional[str] = None,
from_date: Optional[datetime] = None,
to_date: Optional[datetime] = None,
message_stream: Optional[str] = None,
type: BounceType | None = None,
inactive: bool | None = None,
email_filter: str | None = None,
tag: str | None = None,
message_id: str | None = None,
from_date: datetime | None = None,
to_date: datetime | None = None,
message_stream: str | None = None,
) -> AsyncGenerator[Bounce, None]:
"""Yield bounces with automatic pagination."""
async for bounce in paginate(
Expand Down
9 changes: 4 additions & 5 deletions postmark/models/bounces/schemas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, ConfigDict, EmailStr, Field

Expand All @@ -13,7 +12,7 @@ class Bounce(BaseModel):
type: BounceType = Field(alias="Type")
type_code: int = Field(alias="TypeCode")
name: str = Field(alias="Name")
tag: Optional[str] = Field(None, alias="Tag")
tag: str | None = Field(None, alias="Tag")
message_id: str = Field(alias="MessageID")
server_id: int = Field(alias="ServerID")
message_stream: str = Field(alias="MessageStream")
Expand All @@ -26,7 +25,7 @@ class Bounce(BaseModel):
inactive: bool = Field(alias="Inactive")
can_activate: bool = Field(alias="CanActivate")
subject: str = Field(alias="Subject")
content: Optional[str] = Field(None, alias="Content")
content: str | None = Field(None, alias="Content")

model_config = ConfigDict(populate_by_name=True)

Expand All @@ -46,7 +45,7 @@ class DeliveryStats(BaseModel):
"""Response from ``GET /deliverystats``"""

inactive_mails: int = Field(alias="InactiveMails")
bounces: List[BounceTypeCount] = Field(alias="Bounces")
bounces: list[BounceTypeCount] = Field(alias="Bounces")

model_config = ConfigDict(populate_by_name=True)

Expand All @@ -55,7 +54,7 @@ class BouncesListResponse(BaseModel):
"""Response from ``GET /bounces``"""

total_count: int = Field(alias="TotalCount")
bounces: List[Bounce] = Field(alias="Bounces")
bounces: list[Bounce] = Field(alias="Bounces")

model_config = ConfigDict(populate_by_name=True)

Expand Down
6 changes: 2 additions & 4 deletions postmark/models/domains/manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from postmark.models.page import Page
from postmark.utils.types import HTTPClient

Expand Down Expand Up @@ -42,7 +40,7 @@ async def get(self, domain_id: int) -> Domain:
async def create(
self,
name: str,
return_path_domain: Optional[str] = None,
return_path_domain: str | None = None,
) -> Domain:
"""
Create a new domain on the account.
Expand All @@ -62,7 +60,7 @@ async def create(
async def edit(
self,
domain_id: int,
return_path_domain: Optional[str] = None,
return_path_domain: str | None = None,
) -> Domain:
"""
Update a domain.
Expand Down
30 changes: 14 additions & 16 deletions postmark/models/domains/schemas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List, Optional

from pydantic import BaseModel, ConfigDict, Field


Expand All @@ -22,25 +20,25 @@ class Domain(BaseModel):
id: int = Field(alias="ID")
name: str = Field(alias="Name")
spf_verified: bool = Field(False, alias="SPFVerified") # deprecated by Postmark
spf_host: Optional[str] = Field(None, alias="SPFHost")
spf_text_value: Optional[str] = Field(None, alias="SPFTextValue")
spf_host: str | None = Field(None, alias="SPFHost")
spf_text_value: str | None = Field(None, alias="SPFTextValue")
dkim_verified: bool = Field(alias="DKIMVerified")
weak_dkim: bool = Field(alias="WeakDKIM")
dkim_host: Optional[str] = Field(None, alias="DKIMHost")
dkim_text_value: Optional[str] = Field(None, alias="DKIMTextValue")
dkim_pending_host: Optional[str] = Field(None, alias="DKIMPendingHost")
dkim_pending_text_value: Optional[str] = Field(None, alias="DKIMPendingTextValue")
dkim_revoked_host: Optional[str] = Field(None, alias="DKIMRevokedHost")
dkim_revoked_text_value: Optional[str] = Field(None, alias="DKIMRevokedTextValue")
safe_to_remove_revoked_key_from_dns: Optional[bool] = Field(
dkim_host: str | None = Field(None, alias="DKIMHost")
dkim_text_value: str | None = Field(None, alias="DKIMTextValue")
dkim_pending_host: str | None = Field(None, alias="DKIMPendingHost")
dkim_pending_text_value: str | None = Field(None, alias="DKIMPendingTextValue")
dkim_revoked_host: str | None = Field(None, alias="DKIMRevokedHost")
dkim_revoked_text_value: str | None = Field(None, alias="DKIMRevokedTextValue")
safe_to_remove_revoked_key_from_dns: bool | None = Field(
None, alias="SafeToRemoveRevokedKeyFromDNS"
)
dkim_update_status: Optional[str] = Field(None, alias="DKIMUpdateStatus")
return_path_domain: Optional[str] = Field(None, alias="ReturnPathDomain")
return_path_domain_verified: Optional[bool] = Field(
dkim_update_status: str | None = Field(None, alias="DKIMUpdateStatus")
return_path_domain: str | None = Field(None, alias="ReturnPathDomain")
return_path_domain_verified: bool | None = Field(
None, alias="ReturnPathDomainVerified"
)
return_path_domain_cname_value: Optional[str] = Field(
return_path_domain_cname_value: str | None = Field(
None, alias="ReturnPathDomainCNAMEValue"
)

Expand All @@ -51,7 +49,7 @@ class DomainsListResponse(BaseModel):
"""Response from ``GET /domains``."""

total_count: int = Field(alias="TotalCount")
domains: List[DomainListItem] = Field(alias="Domains")
domains: list[DomainListItem] = Field(alias="Domains")

model_config = ConfigDict(populate_by_name=True)

Expand Down
20 changes: 10 additions & 10 deletions postmark/models/inbound/manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Any, Dict, Optional
from typing import Any

from postmark.models.page import Page
from postmark.utils.types import HTTPClient
Expand All @@ -15,22 +15,22 @@ async def list(
self,
count: int = 100,
offset: int = 0,
recipient: Optional[str] = None,
from_email: Optional[str] = None,
tag: Optional[str] = None,
subject: Optional[str] = None,
mailbox_hash: Optional[str] = None,
status: Optional[str] = None,
from_date: Optional[datetime] = None,
to_date: Optional[datetime] = None,
recipient: str | None = None,
from_email: str | None = None,
tag: str | None = None,
subject: str | None = None,
mailbox_hash: str | None = None,
status: str | None = None,
from_date: datetime | None = None,
to_date: datetime | None = None,
) -> Page[InboundMessage]:
"""List inbound messages."""
if count > 500:
raise ValueError("Count cannot exceed 500 per request")
if count + offset > 10000:
raise ValueError("Count + Offset cannot exceed 10,000")

params: Dict[str, Any] = {"count": count, "offset": offset}
params: dict[str, Any] = {"count": count, "offset": offset}

if recipient is not None:
params["recipient"] = recipient
Expand Down
Loading