Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f33e194
perf(client): optimize file structure copying in multipart requests
stainless-app[bot] Apr 18, 2026
5be9e53
chore(internal): more robust bootstrap script
stainless-app[bot] Apr 23, 2026
4b98bee
fix: use correct field name format for multipart file arrays
stainless-app[bot] Apr 28, 2026
111bbaa
feat: support setting headers via env
stainless-app[bot] Apr 28, 2026
51c981a
codegen metadata
stainless-app[bot] May 1, 2026
f6dc2ec
codegen metadata
stainless-app[bot] May 1, 2026
9d75a30
chore(internal): reformat pyproject.toml
stainless-app[bot] May 1, 2026
ee15d9a
fix(client): add missing f-string prefix in file type error message
stainless-app[bot] May 9, 2026
87f6e77
feat(internal/types): support eagerly validating pydantic iterators
stainless-app[bot] May 12, 2026
444d644
ci: pin GitHub Actions to commit SHAs
stainless-app[bot] May 13, 2026
f352f50
feat(api): add journey CRUD/versioning/templates endpoints, update types
stainless-app[bot] May 14, 2026
3238616
feat: [SUP-607] Add DELETE endpoint for Courier Create tenant templates
stainless-app[bot] May 15, 2026
6a53a40
codegen metadata
stainless-app[bot] May 18, 2026
ab1097c
codegen metadata
stainless-app[bot] May 18, 2026
978c447
codegen metadata
stainless-app[bot] May 18, 2026
89507e7
codegen metadata
stainless-app[bot] May 18, 2026
974e8c8
feat: [C-18380] Journeys API reference: copy + naming cleanup
stainless-app[bot] May 19, 2026
af92887
codegen metadata
stainless-app[bot] May 19, 2026
00a1252
release: 7.12.0
stainless-app[bot] May 19, 2026
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ${{ github.repository == 'stainless-sdks/courier-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Install Rye
run: |
Expand All @@ -46,7 +46,7 @@ jobs:
id-token: write
runs-on: ${{ github.repository == 'stainless-sdks/courier-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Install Rye
run: |
Expand All @@ -67,7 +67,7 @@ jobs:
github.repository == 'stainless-sdks/courier-python' &&
!startsWith(github.ref, 'refs/heads/stl/')
id: github-oidc
uses: actions/github-script@v8
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: core.setOutput('github_token', await core.getIDToken());

Expand All @@ -87,7 +87,7 @@ jobs:
runs-on: ${{ github.repository == 'stainless-sdks/courier-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Install Rye
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Install Rye
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
if: github.repository == 'trycourier/courier-python' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')

steps:
- uses: actions/checkout@v6
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Check release environment
run: |
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "7.11.2"
".": "7.12.0"
}
8 changes: 4 additions & 4 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 103
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier%2Fcourier-3f78581b4e078a1f620d9f587f18d77bcde6d20f56b0e4ae798648f4236494fb.yml
openapi_spec_hash: 6bd33e0396d85e11bb46f0d549af93a3
config_hash: afcc4f6f8c33ca3f338589e32e086f56
configured_endpoints: 117
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier/courier-8e7ad3d889c555ff9c381518b627b24b85e3eb7376bdc3689adc7a96ec78e537.yml
openapi_spec_hash: 53b3680aae719487c56efaa782bbe5b2
config_hash: 10bd597dd6cc89023541bc551b6532b8
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog

## 7.12.0 (2026-05-19)

Full Changelog: [v7.11.2...v7.12.0](https://github.com/trycourier/courier-python/compare/v7.11.2...v7.12.0)

### Features

* [C-18380] Journeys API reference: copy + naming cleanup ([974e8c8](https://github.com/trycourier/courier-python/commit/974e8c8bd203e9c497bdf4d7c1ecb5454e2acc7d))
* [SUP-607] Add DELETE endpoint for Courier Create tenant templates ([3238616](https://github.com/trycourier/courier-python/commit/3238616527f879b97342e9ea9a4ac92ea99f4081))
* **api:** add journey CRUD/versioning/templates endpoints, update types ([f352f50](https://github.com/trycourier/courier-python/commit/f352f50dde5c78a96ac7f12f1358d71dcc637ee3))
* **internal/types:** support eagerly validating pydantic iterators ([87f6e77](https://github.com/trycourier/courier-python/commit/87f6e77c795a9eb8a0c51586401a9129ecc0a9f9))
* support setting headers via env ([111bbaa](https://github.com/trycourier/courier-python/commit/111bbaa73c526cac005398950f3357631203fb4e))


### Bug Fixes

* **client:** add missing f-string prefix in file type error message ([ee15d9a](https://github.com/trycourier/courier-python/commit/ee15d9a08a7aa77c6daba0402545b3f9d7d95333))
* use correct field name format for multipart file arrays ([4b98bee](https://github.com/trycourier/courier-python/commit/4b98beed2c666bebce1ddb8b1d8cccb68c40ffb6))


### Performance Improvements

* **client:** optimize file structure copying in multipart requests ([f33e194](https://github.com/trycourier/courier-python/commit/f33e194bd4cf761f56d37371b0a778b2bd72938b))


### Chores

* **internal:** more robust bootstrap script ([5be9e53](https://github.com/trycourier/courier-python/commit/5be9e537dd664f954d4a5348d8dc39f694972fb8))
* **internal:** reformat pyproject.toml ([9d75a30](https://github.com/trycourier/courier-python/commit/9d75a3001d33be94d2942066c793ea828f84af0c))

## 7.11.2 (2026-04-14)

Full Changelog: [v7.11.1...v7.11.2](https://github.com/trycourier/courier-python/compare/v7.11.1...v7.11.2)
Expand Down
52 changes: 50 additions & 2 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,36 @@ Types:

```python
from courier.types import (
CreateJourneyRequest,
Journey,
JourneyAINode,
JourneyAPIInvokeTriggerNode,
JourneyConditionAtom,
JourneyConditionGroup,
JourneyConditionNestedGroup,
JourneyConditionsField,
JourneyDelayDurationNode,
JourneyDelayUntilNode,
JourneyExitNode,
JourneyFetchGetDeleteNode,
JourneyFetchPostPutNode,
JourneyMergeStrategy,
JourneyNode,
JourneyPublishRequest,
JourneyResponse,
JourneySegmentTriggerNode,
JourneySendNode,
JourneyState,
JourneyTemplateCreateRequest,
JourneyTemplateGetResponse,
JourneyTemplateListResponse,
JourneyTemplatePublishRequest,
JourneyTemplateReplaceRequest,
JourneyTemplateSummary,
JourneyThrottleDynamicNode,
JourneyThrottleStaticNode,
JourneyVersionItem,
JourneyVersionsListResponse,
JourneysInvokeRequest,
JourneysInvokeResponse,
JourneysListResponse,
Expand All @@ -206,8 +235,26 @@ from courier.types import (

Methods:

- <code title="get /journeys">client.journeys.<a href="./src/courier/resources/journeys.py">list</a>(\*\*<a href="src/courier/types/journey_list_params.py">params</a>) -> <a href="./src/courier/types/journeys_list_response.py">JourneysListResponse</a></code>
- <code title="post /journeys/{templateId}/invoke">client.journeys.<a href="./src/courier/resources/journeys.py">invoke</a>(template_id, \*\*<a href="src/courier/types/journey_invoke_params.py">params</a>) -> <a href="./src/courier/types/journeys_invoke_response.py">JourneysInvokeResponse</a></code>
- <code title="post /journeys">client.journeys.<a href="./src/courier/resources/journeys/journeys.py">create</a>(\*\*<a href="src/courier/types/journey_create_params.py">params</a>) -> <a href="./src/courier/types/journey_response.py">JourneyResponse</a></code>
- <code title="get /journeys/{templateId}">client.journeys.<a href="./src/courier/resources/journeys/journeys.py">retrieve</a>(template_id, \*\*<a href="src/courier/types/journey_retrieve_params.py">params</a>) -> <a href="./src/courier/types/journey_response.py">JourneyResponse</a></code>
- <code title="get /journeys">client.journeys.<a href="./src/courier/resources/journeys/journeys.py">list</a>(\*\*<a href="src/courier/types/journey_list_params.py">params</a>) -> <a href="./src/courier/types/journeys_list_response.py">JourneysListResponse</a></code>
- <code title="delete /journeys/{templateId}">client.journeys.<a href="./src/courier/resources/journeys/journeys.py">archive</a>(template_id) -> None</code>
- <code title="post /journeys/{templateId}/invoke">client.journeys.<a href="./src/courier/resources/journeys/journeys.py">invoke</a>(template_id, \*\*<a href="src/courier/types/journey_invoke_params.py">params</a>) -> <a href="./src/courier/types/journeys_invoke_response.py">JourneysInvokeResponse</a></code>
- <code title="get /journeys/{templateId}/versions">client.journeys.<a href="./src/courier/resources/journeys/journeys.py">list_versions</a>(template_id) -> <a href="./src/courier/types/journey_versions_list_response.py">JourneyVersionsListResponse</a></code>
- <code title="post /journeys/{templateId}/publish">client.journeys.<a href="./src/courier/resources/journeys/journeys.py">publish</a>(template_id, \*\*<a href="src/courier/types/journey_publish_params.py">params</a>) -> <a href="./src/courier/types/journey_response.py">JourneyResponse</a></code>
- <code title="put /journeys/{templateId}">client.journeys.<a href="./src/courier/resources/journeys/journeys.py">replace</a>(template_id, \*\*<a href="src/courier/types/journey_replace_params.py">params</a>) -> <a href="./src/courier/types/journey_response.py">JourneyResponse</a></code>

## Templates

Methods:

- <code title="post /journeys/{templateId}/templates">client.journeys.templates.<a href="./src/courier/resources/journeys/templates.py">create</a>(template_id, \*\*<a href="src/courier/types/journeys/template_create_params.py">params</a>) -> <a href="./src/courier/types/journey_template_get_response.py">JourneyTemplateGetResponse</a></code>
- <code title="get /journeys/{templateId}/templates/{notificationId}">client.journeys.templates.<a href="./src/courier/resources/journeys/templates.py">retrieve</a>(notification_id, \*, template_id) -> <a href="./src/courier/types/journey_template_get_response.py">JourneyTemplateGetResponse</a></code>
- <code title="get /journeys/{templateId}/templates">client.journeys.templates.<a href="./src/courier/resources/journeys/templates.py">list</a>(template_id, \*\*<a href="src/courier/types/journeys/template_list_params.py">params</a>) -> <a href="./src/courier/types/journey_template_list_response.py">JourneyTemplateListResponse</a></code>
- <code title="delete /journeys/{templateId}/templates/{notificationId}">client.journeys.templates.<a href="./src/courier/resources/journeys/templates.py">archive</a>(notification_id, \*, template_id) -> None</code>
- <code title="get /journeys/{templateId}/templates/{notificationId}/versions">client.journeys.templates.<a href="./src/courier/resources/journeys/templates.py">list_versions</a>(notification_id, \*, template_id) -> <a href="./src/courier/types/notification_template_version_list_response.py">NotificationTemplateVersionListResponse</a></code>
- <code title="post /journeys/{templateId}/templates/{notificationId}/publish">client.journeys.templates.<a href="./src/courier/resources/journeys/templates.py">publish</a>(notification_id, \*, template_id, \*\*<a href="src/courier/types/journeys/template_publish_params.py">params</a>) -> None</code>
- <code title="put /journeys/{templateId}/templates/{notificationId}">client.journeys.templates.<a href="./src/courier/resources/journeys/templates.py">replace</a>(notification_id, \*, template_id, \*\*<a href="src/courier/types/journeys/template_replace_params.py">params</a>) -> <a href="./src/courier/types/journey_template_get_response.py">JourneyTemplateGetResponse</a></code>

# Brands

Expand Down Expand Up @@ -501,6 +548,7 @@ Methods:

- <code title="get /tenants/{tenant_id}/templates/{template_id}">client.tenants.templates.<a href="./src/courier/resources/tenants/templates/templates.py">retrieve</a>(template_id, \*, tenant_id) -> <a href="./src/courier/types/base_template_tenant_association.py">BaseTemplateTenantAssociation</a></code>
- <code title="get /tenants/{tenant_id}/templates">client.tenants.templates.<a href="./src/courier/resources/tenants/templates/templates.py">list</a>(tenant_id, \*\*<a href="src/courier/types/tenants/template_list_params.py">params</a>) -> <a href="./src/courier/types/tenants/template_list_response.py">TemplateListResponse</a></code>
- <code title="delete /tenants/{tenant_id}/templates/{template_id}">client.tenants.templates.<a href="./src/courier/resources/tenants/templates/templates.py">delete</a>(template_id, \*, tenant_id) -> None</code>
- <code title="post /tenants/{tenant_id}/templates/{template_id}/publish">client.tenants.templates.<a href="./src/courier/resources/tenants/templates/templates.py">publish</a>(template_id, \*, tenant_id, \*\*<a href="src/courier/types/tenants/template_publish_params.py">params</a>) -> <a href="./src/courier/types/post_tenant_template_publish_response.py">PostTenantTemplatePublishResponse</a></code>
- <code title="put /tenants/{tenant_id}/templates/{template_id}">client.tenants.templates.<a href="./src/courier/resources/tenants/templates/templates.py">replace</a>(template_id, \*, tenant_id, \*\*<a href="src/courier/types/tenants/template_replace_params.py">params</a>) -> <a href="./src/courier/types/put_tenant_template_response.py">PutTenantTemplateResponse</a></code>

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "trycourier"
version = "7.11.2"
version = "7.12.0"
description = "The official Python library for the Courier API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down Expand Up @@ -168,7 +168,7 @@ show_error_codes = true
#
# We also exclude our `tests` as mypy doesn't always infer
# types correctly and Pyright will still catch any type errors.
exclude = ['src/courier/_files.py', '_dev/.*.py', 'tests/.*']
exclude = ["src/courier/_files.py", "_dev/.*.py", "tests/.*"]

strict_equality = true
implicit_reexport = true
Expand Down
2 changes: 1 addition & 1 deletion scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

cd "$(dirname "$0")/.."

if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] && [ -t 0 ]; then
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "${SKIP_BREW:-}" != "1" ] && [ -t 0 ]; then
brew bundle check >/dev/null 2>&1 || {
echo -n "==> Install Homebrew dependencies? (y/N): "
read -r response
Expand Down
26 changes: 24 additions & 2 deletions src/courier/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
RequestOptions,
not_given,
)
from ._utils import is_given, get_async_library
from ._utils import (
is_given,
is_mapping_t,
get_async_library,
)
from ._compat import cached_property
from ._version import __version__
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
Expand Down Expand Up @@ -57,7 +61,6 @@
from .resources.send import SendResource, AsyncSendResource
from .resources.brands import BrandsResource, AsyncBrandsResource
from .resources.inbound import InboundResource, AsyncInboundResource
from .resources.journeys import JourneysResource, AsyncJourneysResource
from .resources.messages import MessagesResource, AsyncMessagesResource
from .resources.requests import RequestsResource, AsyncRequestsResource
from .resources.audiences import AudiencesResource, AsyncAudiencesResource
Expand All @@ -66,6 +69,7 @@
from .resources.audit_events import AuditEventsResource, AsyncAuditEventsResource
from .resources.translations import TranslationsResource, AsyncTranslationsResource
from .resources.tenants.tenants import TenantsResource, AsyncTenantsResource
from .resources.journeys.journeys import JourneysResource, AsyncJourneysResource
from .resources.profiles.profiles import ProfilesResource, AsyncProfilesResource
from .resources.routing_strategies import RoutingStrategiesResource, AsyncRoutingStrategiesResource
from .resources.providers.providers import ProvidersResource, AsyncProvidersResource
Expand Down Expand Up @@ -119,6 +123,15 @@ def __init__(
if base_url is None:
base_url = f"https://api.courier.com"

custom_headers_env = os.environ.get("COURIER_CUSTOM_HEADERS")
if custom_headers_env is not None:
parsed: dict[str, str] = {}
for line in custom_headers_env.split("\n"):
colon = line.find(":")
if colon >= 0:
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}

super().__init__(
version=__version__,
base_url=base_url,
Expand Down Expand Up @@ -401,6 +414,15 @@ def __init__(
if base_url is None:
base_url = f"https://api.courier.com"

custom_headers_env = os.environ.get("COURIER_CUSTOM_HEADERS")
if custom_headers_env is not None:
parsed: dict[str, str] = {}
for line in custom_headers_env.split("\n"):
colon = line.find(":")
if colon >= 0:
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}

super().__init__(
version=__version__,
base_url=base_url,
Expand Down
58 changes: 54 additions & 4 deletions src/courier/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import io
import os
import pathlib
from typing import overload
from typing_extensions import TypeGuard
from typing import Sequence, cast, overload
from typing_extensions import TypeVar, TypeGuard

import anyio

Expand All @@ -17,7 +17,9 @@
HttpxFileContent,
HttpxRequestFiles,
)
from ._utils import is_tuple_t, is_mapping_t, is_sequence_t
from ._utils import is_list, is_mapping, is_tuple_t, is_mapping_t, is_sequence_t

_T = TypeVar("_T")


def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
Expand Down Expand Up @@ -97,7 +99,7 @@ async def async_to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles
elif is_sequence_t(files):
files = [(key, await _async_transform_file(file)) for key, file in files]
else:
raise TypeError("Unexpected file type input {type(files)}, expected mapping or sequence")
raise TypeError(f"Unexpected file type input {type(files)}, expected mapping or sequence")

return files

Expand All @@ -121,3 +123,51 @@ async def async_read_file_content(file: FileContent) -> HttpxFileContent:
return await anyio.Path(file).read_bytes()

return file


def deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]]) -> _T:
"""Copy only the containers along the given paths.

Used to guard against mutation by extract_files without copying the entire structure.
Only dicts and lists that lie on a path are copied; everything else
is returned by reference.

For example, given paths=[["foo", "files", "file"]] and the structure:
{
"foo": {
"bar": {"baz": {}},
"files": {"file": <content>}
}
}
The root dict, "foo", and "files" are copied (they lie on the path).
"bar" and "baz" are returned by reference (off the path).
"""
return _deepcopy_with_paths(item, paths, 0)


def _deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]], index: int) -> _T:
if not paths:
return item
if is_mapping(item):
key_to_paths: dict[str, list[Sequence[str]]] = {}
for path in paths:
if index < len(path):
key_to_paths.setdefault(path[index], []).append(path)

# if no path continues through this mapping, it won't be mutated and copying it is redundant
if not key_to_paths:
return item

result = dict(item)
for key, subpaths in key_to_paths.items():
if key in result:
result[key] = _deepcopy_with_paths(result[key], subpaths, index + 1)
return cast(_T, result)
if is_list(item):
array_paths = [path for path in paths if index < len(path) and path[index] == "<array>"]

# if no path expects a list here, nothing will be mutated inside it - return by reference
if not array_paths:
return cast(_T, item)
return cast(_T, [_deepcopy_with_paths(entry, array_paths, index + 1) for entry in item])
return item
Loading