Skip to content

Commit

Permalink
version 15.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
klaviyo-sdk committed Nov 19, 2024
1 parent e0bba51 commit 0f8438f
Show file tree
Hide file tree
Showing 47 changed files with 6,076 additions and 5,536 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

NOTE: For more granular API-specific changes, please see our [API Changelog](https://developers.klaviyo.com/en/docs/changelog_)

## [15.0.0] - 2024-10-15
### Added
- Lazy imports (optional)
- Set `KLAVIYO_PYTHON_SDK_LAZY_IMPORTS` environment variable to `true` to use lazy imports, which will reduce initial load time of library
- Note that using this option may break imports from `openapi_client`
- See [README](https://github.com/klaviyo/klaviyo-api-python-internal/blob/main/README.md#lazy-imports) for more details
### Changed
- **Breaking:** renamed several models:
- `GetCampaignMessageTemplateRelationshipListResponse` -> `GetCampaignMessageTemplateRelationshipResponse`
- `GetListFlowTriggersRelationshipResponseCollection` -> `GetListFlowTriggersRelationshipsResponseCollection`
- `GetMetricFlowTriggersRelationshipResponseCollection` -> `GetMetricFlowTriggersRelationshipsResponseCollection`
- `PostListCreateResponseDataRelationshipsFlowTriggers` -> `GetMetricResponseCollectionCompoundDocumentDataInnerAllOfRelationshipsFlowTriggers`
- `GetMetricFlowTriggersRelationshipResponseCollectionDataInner` -> `GetMetricResponseCollectionCompoundDocumentDataInnerAllOfRelationshipsFlowTriggersDataInner`

## [14.0.0] - 2024-10-15
### Added
- Universal Content API
Expand Down
156 changes: 151 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Klaviyo Python SDK

- SDK version: 14.0.0
- SDK version: 15.0.0
- API revision: 2024-10-15

## Table of Contents
Expand Down Expand Up @@ -44,6 +44,11 @@
* [Parameters & Arguments](#parameters--arguments)
* [Namespace](#namespace)
* [Renamed Fields](#renamed-fields)
* [Filter Builder](#filter-builder)
* [Typed Responses](#typed-responses)
* [Backwards Compatibility](#backwards-compatibility)
* [Untyped Response Data for Specific APIs](#untyped-response-data-for-specific-apis)
* [Lazy Imports](#lazy-imports)
<!-- TOC -->

## Helpful Resources
Expand Down Expand Up @@ -3367,11 +3372,15 @@ klaviyo.Profiles.create_profile_suppression_bulk_delete_job(body)

# body | dict

klaviyo.Profiles.create_or_update_profile(body)
## Keyword Arguments

# additional_fields_profile | List[str]

klaviyo.Profiles.create_or_update_profile(body, additional_fields_profile=additional_fields_profile)
```
##### Method alias:
```python
klaviyo.Profiles.create_profile_import(body)
klaviyo.Profiles.create_profile_import(body, additional_fields_profile=additional_fields_profile)
```


Expand All @@ -3384,7 +3393,11 @@ klaviyo.Profiles.create_profile_import(body)

# body | dict

klaviyo.Profiles.create_profile(body)
## Keyword Arguments

# additional_fields_profile | List[str]

klaviyo.Profiles.create_profile(body, additional_fields_profile=additional_fields_profile)
```


Expand Down Expand Up @@ -3829,7 +3842,11 @@ klaviyo.Profiles.create_profile_bulk_import_job(body)
# id | str
# body | dict

klaviyo.Profiles.update_profile(id, body)
## Keyword Arguments

# additional_fields_profile | List[str]

klaviyo.Profiles.update_profile(id, body, additional_fields_profile=additional_fields_profile)
```


Expand Down Expand Up @@ -5090,4 +5107,133 @@ class StaticScheduleOptions(BaseModel):
```python
schedule_options = StaticScheduleOptions(datetime_=datetime.datetime.strptime("2024-05-19T00:00:00+00:00", "%Y-%m-%dT%H:%M:%S%z")
print(schedule_options.datetime_)
```

## Filter Builder
Use this class to help construct filter query parameters.
```python
old_date = datetime.datetime(2023, 8, 15, 12, 30, 0, 0, tzinfo=datetime.timezone.utc)

f = FilterBuilder()
f.any("email", ["[email protected]", "[email protected]"])
f.greater_than("created", old_date)

# f.build() returns 'any(email,["[email protected]","[email protected]"]),greater-than(created,2023-08-15T12:30:00+00:00)'
profile_response = client.Profiles.get_profiles(filter=f.build())

# You can also chain FilterBuilder methods
f = FilterBuilder()
filters = f.any("email", ["[email protected]", "[email protected]"]).greater_than("created", date).build()
assert filters == "any(email,['[email protected]','[email protected]']),greater-than(created,2023-08-15T12:30:00+00:00)"
```

## Typed Responses
By default, all API methods will return a type representing the response payload instead of dictionary, as was the case in previous versions of this SDK. Using the typed response, you can access fields of a response using dot notation, like so:
```python
from klaviyo_api import KlaviyoAPI

client = KlaviyoAPI(
api_key,
max_delay=0,
max_retries=0
)

profiles = client.Profiles.get_profiles()
profile_id = profiles.data[0].id
profile = client.Profiles.get_profile(profile_id)
profile_id = profile.data.id
profile_email = profile.data.attributes.email

print(type(profile).__name__) # prints GetProfileResponseCompoundDocument
```
The class used in this example is found [here](src/openapi_client/models/get_profile_response_collection_compound_document.py).

This is a breaking change, as response objects will now require dot notation to access their fields versus the subscriptable access method used for dictionaries, i.e. `profile.data.id` vs `profile['data']['id']`. We have provided a [backwards compatibility strategy](#backwards-compatibility) to smooth the transition from dictionary responses to typed responses.

### Backwards Compatibility
To maintain backwards compatibility with previous versions of this SDK, we have added an `options` argument that allows you to continue using dictionaries as response values. There are two ways to use this `options` argument:
```python
from klaviyo_api import KlaviyoAPI
from openapi_client.api_arg_options import USE_DICTIONARY_FOR_RESPONSE_DATA

client = KlaviyoAPI(
api_key,
max_delay=0,
max_retries=0
)

# 1: Passing options to an individual API method
profiles = client.Profiles.get_profiles(options= {
USE_DICTIONARY_FOR_RESPONSE_DATA: True
})
profile_id = profiles["data"][0]['id']
profile_email = profiles["data"][0]['attributes']['email']

# 2: Passing options to API Client
dictionary_client = KlaviyoAPI(
api_key,
max_delay=0,
max_retries=0,
options={USE_DICTIONARY_FOR_RESPONSE_DATA : True}
)
profiles_ = dictionary_client.Profiles.get_profiles()
profile_0_id = profiles_["data"][0]['id']

profile_0 = dictionary_client.Profiles.get_profile(id=profile_0_id)
profile_0_email = profile_0["data"]['attributes']['email']
```
The first way will only return a dictionary for that specific `get_profiles` call. The second makes it so that all API methods called using `dictionary_client` will return dictionaries as responses.

## Untyped Response Data for Specific APIs
Select APIs do not yet have fully typed responses. Please use our API docs to inspect the schema of the response data for the following APIs.
- **Segments** - The subproperty `conditions` is not yet typed in responses for the following APIs:
- [Create Segment](https://developers.klaviyo.com/en/reference/create_segment)
- [Update Segment](https://developers.klaviyo.com/en/reference/update_segment)
- [Get Segment](https://developers.klaviyo.com/en/reference/get_segment)
- [Get Segments](https://developers.klaviyo.com/en/reference/get_segments)
- The `included` property is not typed in responses for the following APIs:
- [Get Event](https://developers.klaviyo.com/en/reference/get_event)
- [Get Events](https://developers.klaviyo.com/en/reference/get_events)
- [Get Profile](https://developers.klaviyo.com/en/reference/get_profile)
- [Get Profiles](https://developers.klaviyo.com/en/reference/get_profiles)
- [Get Flow](https://developers.klaviyo.com/en/reference/get_flow)
- [Get Flows](https://developers.klaviyo.com/en/reference/get_flows)
- [Get Flow Message](https://developers.klaviyo.com/en/reference/get_flow_message)
- [Get Campaign](https://developers.klaviyo.com/en/reference/get_campaign)
- [Get Campaigns](https://developers.klaviyo.com/en/reference/get_campaigns)
- The `tracking_options` subproperty is not typed in responses for the following APIs:
- [Get Flow Action](https://developers.klaviyo.com/en/reference/get_flow_action)
- [Get Actions for Flow](https://developers.klaviyo.com/en/reference/get_actions_for_flow)
- [Create Campaign](https://developers.klaviyo.com/en/reference/create_campaign)
- [Update Campaign](https://developers.klaviyo.com/en/reference/update_campaign)
- [Get Campaign](https://developers.klaviyo.com/en/reference/get_campaign)
- [Get Campaigns](https://developers.klaviyo.com/en/reference/get_campaigns)
- The `send_options` subproperty is not typed in responses for the following APIs:
- [Create Campaign](https://developers.klaviyo.com/en/reference/create_campaign)
- [Update Campaign](https://developers.klaviyo.com/en/reference/update_campaign)
- [Get Campaign](https://developers.klaviyo.com/en/reference/get_campaign)
- [Get Campaigns](https://developers.klaviyo.com/en/reference/get_campaigns)
- [Get Campaign for Campaign Message](https://developers.klaviyo.com/en/reference/get_campaign_for_campaign_message)
- [Get Messages for Campaign](https://developers.klaviyo.com/en/reference/get_messages_for_campaign)
- The `content` subproperty is not typed in responses for the following APIs:
- [Get Flow Message](https://developers.klaviyo.com/en/reference/get_flow_message)
- [Get Messages for Flow Action](https://developers.klaviyo.com/en/reference/get_messages_for_flow_action)
- [Get Campaign for Campaign Message](https://developers.klaviyo.com/en/reference/get_campaign_for_campaign_message)
- [Get Messages for Campaign](https://developers.klaviyo.com/en/reference/get_messages_for_campaign)


## Lazy Imports
If the `klaviyo_api` import has a long load time, you can set the following environment variable to speed it up:
```shell
export KLAVIYO_PYTHON_SDK_LAZY_IMPORTS=true
```
With this, API classes and models will be imported per-API (e.g. when you use the Profiles API, it only imports profiles-related classes).

**With this setting, you can no longer tersely import from `openapi_client`**. That is, instead of:
```python
from openapi_client import CampaignCreateQuery
```
you will need:
```python
from openapi_client.models.campaign_create_query import CampaignCreateQuery
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openapi_client"
version = "14.0.0"
version = "15.0.0"
description = "Klaviyo API"
authors = ["Klaviyo Developer Experience Team <[email protected]>"]
license = "License"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = klaviyo-api
version = 14.0.0
version = 15.0.0
author = Klaviyo Developers
author_email = [email protected]
description = Klaviyo Python SDK
Expand Down
Loading

0 comments on commit 0f8438f

Please sign in to comment.