Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: Replace OpenAPI generator http code with out own #1654

Merged
merged 41 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
cbd1f89
python: Add new low-level http client
svix-mman Jan 20, 2025
cca4e24
python: Migrate `Application` to new HTTP client
svix-mman Jan 20, 2025
14e8d0f
python: Sort `dashboard_access` in the correct order
svix-mman Jan 20, 2025
97893a3
python: Rename query_params/header_params to an internal method
svix-mman Jan 20, 2025
8255e3a
python: Add `sanitize_field` and `str().lower()` in `*Options._query_…
svix-mman Jan 20, 2025
f4bb9c5
python: For now we only need 1 exception type for HTTP errors
svix-mman Jan 21, 2025
60750da
python: rename `_execute_request` to `_request`
svix-mman Jan 21, 2025
67155e6
python: Add `serialize_params` to `_query_params`/`_header_params`
svix-mman Jan 21, 2025
be34bba
python: Simplify path param url formatting
svix-mman Jan 21, 2025
f0c4a6c
python: Explicit boolean serialization
svix-mman Jan 21, 2025
7de109c
python: Don't generate `_query_params`/`_header_params` if there are …
svix-mman Jan 21, 2025
c93c0d1
python: Implement a default `_header_params` and `_query_params` for …
svix-mman Jan 21, 2025
04ec169
python: `_query_params` and `_header_params` need self (:
svix-mman Jan 21, 2025
ddc30ad
python: Switch `Authentication` to new HTTP client
svix-mman Jan 21, 2025
a4970e3
python: Switch `BackgroundTask` to new codegen
svix-mman Jan 21, 2025
072091f
python: Switch `Endpoint` resource to new HTTP client
svix-mman Jan 21, 2025
6e23c1f
python: Switch `EventType` resource to new HTTP client
svix-mman Jan 21, 2025
1d4c76a
python: Mark `Integration(A)sync`.`get_key` as deprecated
svix-mman Jan 21, 2025
e992a60
python: Switch the `Integration` resource to new HTTP client
svix-mman Jan 21, 2025
ec8092e
python(**Breaking change**): Remove `list` and `list_attempts_for_end…
svix-mman Jan 21, 2025
6374d5c
python: Add `list_by_msg_deprecated` and `list_by_endpoint_deprecated…
svix-mman Jan 21, 2025
743345e
python: (**breaking change**) Remove `MessageListAttemptsForEndpointO…
svix-mman Jan 21, 2025
35b36da
python: Switch `MessageAttempt` to new HTTP client
svix-mman Jan 21, 2025
3e0a99f
python: Switch `Message` resource to use new HTTP client
svix-mman Jan 21, 2025
cd36ffb
python: Switch `Statistics` to new HTTP client
svix-mman Jan 21, 2025
f9b9d16
python: remove `PostOptions` from `OperationalWebhook`
svix-mman Jan 21, 2025
da78242
python: Rename `operational_webhook` to `operational_webhook_endpoint`
svix-mman Jan 21, 2025
6b7ca26
python: (breaking change) Rename these arguments to be inline with th…
svix-mman Jan 21, 2025
2018317
python: Switch `OperationalWebhookEndpoint` to new HTTP client
svix-mman Jan 21, 2025
0071e10
python: Codegen is smart enough to not need to leave `noqa: F841` eve…
svix-mman Jan 22, 2025
03a6f7b
python: Better codegen does not need to ignore unused variable warnings
svix-mman Jan 23, 2025
ecb9202
python: This is the correct way to handel class properties doc comments
svix-mman Jan 23, 2025
1c05e65
python: Document breaking changes
svix-mman Jan 23, 2025
1b5545e
python: Remove these deprecated operations.
svix-mman Jan 23, 2025
ea02fe7
python: Update generated files to use correct doc string format
svix-mman Jan 23, 2025
10942df
This was not really a breaking change
svix-mman Jan 23, 2025
348fcc1
English: Correct syntax error...
svix-mman Jan 23, 2025
db7adbe
python: Move `OperationalWebhook` to new codegen (#1656)
svix-mman Jan 23, 2025
0277b9f
Merge branch 'main' into mendy/add-python-low-level-http-client
svix-mman Jan 23, 2025
f165777
python: Sort these method inline with the codegen
svix-mman Jan 23, 2025
8f204c7
python: Serialize list/set params as a comma separated list
svix-mman Jan 23, 2025
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
53 changes: 27 additions & 26 deletions python/svix/api/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..internal.openapi_client.models.list_response_application_out import (
ListResponseApplicationOut,
)
from .common import ApiBase, BaseOptions, sanitize_field
from .common import ApiBase, BaseOptions, serialize_params


@dataclass
Expand All @@ -21,46 +21,47 @@ class ApplicationListOptions(BaseOptions):
# The sorting order of the returned items
order: t.Optional[models.Ordering] = None

def _query_params(self) -> t.Optional[t.Dict[str, str]]:
d = {
"limit": self.limit,
"iterator": self.iterator,
"order": self.order,
}
return {
k: str(sanitize_field(v)).lower() for k, v in d.items() if v is not None
}
def _query_params(self) -> t.Dict[str, str]:
return serialize_params(
{
"limit": self.limit,
"iterator": self.iterator,
"order": self.order,
}
)

def _header_params(self) -> t.Optional[t.Dict[str, str]]:
return None
def _header_params(self) -> t.Dict[str, str]:
return {}


@dataclass
class ApplicationCreateOptions(BaseOptions):
idempotency_key: t.Optional[str] = None

def _query_params(self) -> t.Optional[t.Dict[str, str]]:
return None
def _query_params(self) -> t.Dict[str, str]:
return {}

def _header_params(self) -> t.Optional[t.Dict[str, str]]:
d = {
"idempotency-key": self.idempotency_key,
}
return {k: v for k, v in d.items() if v is not None}
def _header_params(self) -> t.Dict[str, str]:
return serialize_params(
{
"idempotency-key": self.idempotency_key,
}
)


@dataclass
class ApplicationGetOrCreateOptions(BaseOptions):
idempotency_key: t.Optional[str] = None

def _query_params(self) -> t.Optional[t.Dict[str, str]]:
return None
def _query_params(self) -> t.Dict[str, str]:
return {}

def _header_params(self) -> t.Optional[t.Dict[str, str]]:
d = {
"idempotency-key": self.idempotency_key,
}
return {k: v for k, v in d.items() if v is not None}
def _header_params(self) -> t.Dict[str, str]:
return serialize_params(
{
"idempotency-key": self.idempotency_key,
}
)


class ApplicationAsync(ApiBase):
Expand Down
23 changes: 18 additions & 5 deletions python/svix/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ def sanitize_field(v: t.Any) -> t.Any:
return v


def _serialize_single_param(val: t.Any) -> str:
if isinstance(val, datetime):
if val.tzinfo is None:
val.replace(tzinfo=timezone.utc)
return val.isoformat()
elif isinstance(val, bool):
return str(val).lower()
svix-mman marked this conversation as resolved.
Show resolved Hide resolved
else:
return str(val)


def serialize_params(d: t.Dict[str, t.Optional[t.Any]]) -> t.Dict[str, str]:
return {k: _serialize_single_param(v) for k, v in d.items() if v is not None}


@dataclass
class BaseOptions:
def to_dict(self) -> t.Dict[str, t.Any]:
Expand Down Expand Up @@ -59,11 +74,9 @@ def _get_httpx_kwargs(
header_params: t.Optional[t.Dict[str, str]],
json_body: t.Optional[t.Dict[str, t.Any]],
) -> t.Dict[str, t.Any]:
if path_params is None:
url = f"{self._client.base_url}{path}"
else:
formatted_path = path.format(**path_params)
url = url = f"{self._client.base_url}{formatted_path}"
if path_params is not None:
path = path.format(**path_params)
url = f"{self._client.base_url}{path}"

headers: t.Dict[str, str] = {
**self._client.get_headers(),
Expand Down