{"id":15145720,"url":"https://github.com/klaviyo/klaviyo-python-sdk","last_synced_at":"2025-09-29T15:30:57.577Z","repository":{"id":41953302,"uuid":"438867653","full_name":"klaviyo/klaviyo-python-sdk","owner":"klaviyo","description":"Klaviyo Python SDK","archived":true,"fork":false,"pushed_at":"2023-08-18T15:23:21.000Z","size":173,"stargazers_count":13,"open_issues_count":2,"forks_count":3,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-01-11T04:57:57.553Z","etag":null,"topics":["bigcommerce","ecommerce","email","klaviyo","magento","prestashop","push","shopify","sms","woocommerce"],"latest_commit_sha":null,"homepage":"https://developers.klaviyo.com/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klaviyo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-16T05:12:31.000Z","updated_at":"2023-09-04T11:45:13.000Z","dependencies_parsed_at":"2024-09-25T09:02:07.917Z","dependency_job_id":"20c3d5ff-5bfe-4595-92c4-b259832fba62","html_url":"https://github.com/klaviyo/klaviyo-python-sdk","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":0.3157894736842105,"last_synced_commit":"3ef92b44bf620eee311c24020534537f947d496a"},"previous_names":["klaviyo/klaviyo-python"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaviyo%2Fklaviyo-python-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaviyo%2Fklaviyo-python-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaviyo%2Fklaviyo-python-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaviyo%2Fklaviyo-python-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klaviyo","download_url":"https://codeload.github.com/klaviyo/klaviyo-python-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234517694,"owners_count":18845676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bigcommerce","ecommerce","email","klaviyo","magento","prestashop","push","shopify","sms","woocommerce"],"created_at":"2024-09-26T11:42:04.836Z","updated_at":"2025-09-29T15:30:57.245Z","avatar_url":"https://github.com/klaviyo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Klaviyo Python SDK (Legacy)\n\n## Legacy Notice\n\nThis SDK is set to be deprecated + retired on 2024-06-30.\n\nWe have a NEW python SDK to go along with our [new API](https://developers.klaviyo.com/en/reference/api_overview).\n\nWe recommend migrating over to our [newest SDK](https://github.com/klaviyo/klaviyo-api-python).\n\nYou can read more about our SDK release history and support [here](https://developers.klaviyo.com/en/docs/sdk_overview)\n\nFor a comparison between our old and new APIs, check out [this guide](https://developers.klaviyo.com/en/docs/apis_comparison_chart).\n\n# Klaviyo Python SDK\n\n- SDK version: 1.0.7.20220329\n\n## Helpful Resources\n\n- [API Reference](https://developers.klaviyo.com/en/reference/api-overview)\n- [API Guides](https://developers.klaviyo.com/en/docs)\n- [Postman Workspace](https://www.postman.com/klaviyo/workspace/klaviyo-developers)\n\n## Design \u0026 Approach\n\nThis SDK is a thin wrapper around our API. See our API Reference for full documentation on API behavior.\n\nThis SDK exactly mirrors the organization and naming convention of the above language-agnostic resources, with a few namespace changes to make it Pythonic (details in Appendix).\n\n## Organization\n\nThis SDK is organized into the following resources:\n\n- Campaigns\n- DataPrivacy\n- ListsSegments\n- Metrics\n- Profiles\n- Templates\n- TrackIdentify\n\n# Installation\n\n## pip\n\nYou can install this library using [`pip`](https://pypi.org/project/klaviyo-sdk/).\n\nDepending on your system configuration, you will need to run *one* of the following shell commands:\n\n`pip install klaviyo-sdk`\n\nOR \n\n`pip3 install klaviyo-sdk`\n\n## source code\n\n*Alternatively*, you can also run this using this repo as source code, by running *one* of the following shell commands within the cloned repo:\n\n`pip install -r requirements.txt`\n\nOR\n\n`pip3 install -r requirements.txt`\n\n\nand then running python from the cloned repo.\n\n# Usage Example\n\n### To instantiate the client\n\n```python\nfrom klaviyo_sdk import Client\n\nclient = Client( \"YOUR API KEY HERE\", max_delay=60, max_retries=3)\n```\n\nNOTE: \n* The SDK retries on resolvable errors, namely: rate limits (common) and server errors on klaviyo (rare).\n* The keyword arguments define retry behavior; the example is populated with the default values.\n* `max_delay` denotes total delay (in seconds) across all attempts.\n\n### To call the `metric-export` operation:\n\n```python\nmetric_id = \"METRIC_ID\"\ncount = 100\n\nclient.Metrics.metric_export(metric_id, count=count) \n```\n\n# Error Handling\n\nThis SDK throws an `ApiException` error when the server returns a non-`2XX` response. \n\nAn `ApiException` consists of the following attributes:\n\n* `status` : `int`\n* `reason` : `str`\n* `body` : `bytes`\n    * this can be decoded into a native python dictionary as follows:\n        ```python\n        # to decode to a dictionary\n        import json\n        BODY_DICT = json.loads(YOUR_EXCEPTION.body)\n\n        # to decode to a string\n        BODY_STRING = YOUR_EXCEPTION.body.decode('utf-8')\n        ```\n* `headers` : [class 'urllib3._collections.HTTPHeaderDict'](https://urllib3.readthedocs.io/en/stable/user-guide.html?highlight=httpheaderdict#response-content)\n    * This can be interacted with as a normal dictionary:\n        * ex:\n            ```\n            date = YOUR_EXCEPTION.headers['Date']\n            keys = YOUR_EXCEPTION.headers.keys()\n            values = YOUR_EXCEPTION.headers.values()\n            ```\n\n# Comprehensive list of Operations \u0026 Parameters\n\n_**NOTE:**_\n- Organization: Resource groups and operation_ids are listed in alphabetical order, first by Resource name, then by **OpenAPI Summary**. Operation summaries are those listed in the right side bar of the [API Reference](https://developers.klaviyo.com/en/reference/track-post).\n- For example values / data types, as well as whether parameters are required/optional, please reference the corresponding API Reference link.\n- Some keyword args are required for the API call to succeed, the API docs above are the source of truth regarding which keyword params are required.\n- JSON payloads should be passed in as native python dictionaries.\n\n\n\n## Campaigns\n\n\n#### [Cancel a Campaign](https://developers.klaviyo.com/en/reference/cancel-campaign)\n\n```python\nclient.Campaigns.cancel_campaign(campaign_id)\n```\n\n\n\n\n#### [Clone a Campaign](https://developers.klaviyo.com/en/reference/clone-campaign)\n\n```python\nclient.Campaigns.clone_campaign(campaign_id, name=name, list_id=list_id)\n```\n\n\n\n\n#### [Create New Campaign](https://developers.klaviyo.com/en/reference/create-campaign)\n\n```python\nclient.Campaigns.create_campaign(list_id=list_id, template_id=template_id, from_email=from_email, from_name=from_name, subject=subject, name=name, use_smart_sending=use_smart_sending, add_google_analytics=add_google_analytics)\n```\n\n\n\n\n#### [Get Campaign Info](https://developers.klaviyo.com/en/reference/get-campaign-info)\n\n```python\nclient.Campaigns.get_campaign_info(campaign_id)\n```\n\n\n\n\n#### [Get Campaign Recipients](https://developers.klaviyo.com/en/reference/get-campaign-recipients)\n\n```python\nclient.Campaigns.get_campaign_recipients(campaign_id, count=count, sort=sort, offset=offset)\n```\n\n\n\n\n#### [Get Campaigns](https://developers.klaviyo.com/en/reference/get-campaigns)\n\n```python\nclient.Campaigns.get_campaigns(page=page, count=count)\n```\n\n\n\n\n#### [Schedule a Campaign](https://developers.klaviyo.com/en/reference/schedule-campaign)\n\n```python\nclient.Campaigns.schedule_campaign(campaign_id, send_time=send_time)\n```\n\n\n\n\n#### [Send a Campaign Immediately](https://developers.klaviyo.com/en/reference/send-campaign)\n\n```python\nclient.Campaigns.send_campaign(campaign_id)\n```\n\n\n\n\n#### [Update Campaign](https://developers.klaviyo.com/en/reference/update-campaign)\n\n```python\nclient.Campaigns.update_campaign(campaign_id, list_id=list_id, template_id=template_id, from_email=from_email, from_name=from_name, subject=subject, name=name, use_smart_sending=use_smart_sending, add_google_analytics=add_google_analytics)\n```\n\n\n\n## DataPrivacy\n\n\n#### [Request a Deletion](https://developers.klaviyo.com/en/reference/request-deletion)\n\n```python\nclient.DataPrivacy.request_deletion(body=body)\n```\n\n\n\n## ListsSegments\n\n\n#### [Add Members to a List](https://developers.klaviyo.com/en/reference/add-members)\n\n```python\nclient.ListsSegments.add_members(list_id, body=body)\n```\n\n\n\n\n#### [Create List](https://developers.klaviyo.com/en/reference/create-list)\n\n```python\nclient.ListsSegments.create_list(list_name=list_name)\n```\n\n\n\n\n#### [Delete List](https://developers.klaviyo.com/en/reference/delete-list)\n\n```python\nclient.ListsSegments.delete_list(list_id)\n```\n\n\n\n\n#### [Exclude Profile From All Email](https://developers.klaviyo.com/en/reference/exclude-globally)\n\n```python\nclient.ListsSegments.exclude_globally(email=email)\n```\n\n\n\n\n#### [Get Global Exclusions \u0026 Unsubscribes](https://developers.klaviyo.com/en/reference/get-global-exclusions)\n\n```python\nclient.ListsSegments.get_global_exclusions(reason=reason, sort=sort, count=count, page=page)\n```\n\n\n\n\n#### [Get All Exclusions for a List](https://developers.klaviyo.com/en/reference/get-list-exclusions)\n\n```python\nclient.ListsSegments.get_list_exclusions(list_id, marker=marker)\n```\n\n\n\n\n#### [Get List Info](https://developers.klaviyo.com/en/reference/get-list-info)\n\n```python\nclient.ListsSegments.get_list_info(list_id)\n```\n\n\n\n\n#### [Check if Profiles Are in a List](https://developers.klaviyo.com/en/reference/get-list-members)\n\n```python\nclient.ListsSegments.get_list_members(list_id, body=body)\n```\n\n\n\n\n#### [Check if Profiles Are in a List and not Suppressed](https://developers.klaviyo.com/en/reference/get-list-subscriptions)\n\n```python\nclient.ListsSegments.get_list_subscriptions(list_id, body=body)\n```\n\n\n\n\n#### [Get Lists](https://developers.klaviyo.com/en/reference/get-lists)\n\n```python\nclient.ListsSegments.get_lists()\n```\n\n\n\n\n#### [Get List and Segment Members](https://developers.klaviyo.com/en/reference/get-members)\n\n```python\nclient.ListsSegments.get_members(list_or_segment_id, marker=marker)\n```\n\n\n\n\n#### [Check if Profiles Are in a Segment](https://developers.klaviyo.com/en/reference/get-segment-members)\n\n```python\nclient.ListsSegments.get_segment_members(segment_id, body=body)\n```\n\n\n\n\n#### [Remove Profiles From List](https://developers.klaviyo.com/en/reference/remove-members)\n\n```python\nclient.ListsSegments.remove_members(list_id, body=body)\n```\n\n\n\n\n#### [Subscribe Profiles to List](https://developers.klaviyo.com/en/reference/subscribe)\n\n```python\nclient.ListsSegments.subscribe(list_id, body=body)\n```\n\n\n\n\n#### [Unsubscribe Profiles From List](https://developers.klaviyo.com/en/reference/unsubscribe)\n\n```python\nclient.ListsSegments.unsubscribe(list_id, body=body)\n```\n\n\n\n\n#### [Update List Name](https://developers.klaviyo.com/en/reference/update-list-name)\n\n```python\nclient.ListsSegments.update_list_name(list_id, list_name=list_name)\n```\n\n\n\n## Metrics\n\n\n#### [Get Metrics Info](https://developers.klaviyo.com/en/reference/get-metrics)\n\n```python\nclient.Metrics.get_metrics(page=page, count=count)\n```\n\n\n\n\n#### [Query Event Data](https://developers.klaviyo.com/en/reference/metric-export)\n\n```python\nclient.Metrics.metric_export(metric_id, start_date=start_date, end_date=end_date, unit=unit, measurement=measurement, where=where, by=by, count=count)\n```\n\n\n\n\n#### [Get Events for a Specific Metric](https://developers.klaviyo.com/en/reference/metric-timeline)\n\n```python\nclient.Metrics.metric_timeline(metric_id, since=since, count=count, sort=sort)\n```\n\n\n\n\n#### [Get Events for All Metrics](https://developers.klaviyo.com/en/reference/metrics-timeline)\n\n```python\nclient.Metrics.metrics_timeline(since=since, count=count, sort=sort)\n```\n\n\n\n## Profiles\n\n\n#### [Exchange ID for Profile ID](https://developers.klaviyo.com/en/reference/exchange)\n\n```python\nclient.Profiles.exchange(body=body)\n```\n\n\n\n\n#### [Get Profile](https://developers.klaviyo.com/en/reference/get-profile)\n\n```python\nclient.Profiles.get_profile(person_id)\n```\n\n\n\n\n#### [Get Profile ID](https://developers.klaviyo.com/en/reference/get-profile-id)\n\n```python\nclient.Profiles.get_profile_id(email=email, phone_number=phone_number, external_id=external_id)\n```\n\n\n\n\n#### [Get Profile's Events for a Specific Metric](https://developers.klaviyo.com/en/reference/profile-metric-timeline)\n\n```python\nclient.Profiles.profile_metric_timeline(person_id, metric_id, since=since, count=count, sort=sort)\n```\n\n\n\n\n#### [Get Profile's Events for all Metrics](https://developers.klaviyo.com/en/reference/profile-metrics-timeline)\n\n```python\nclient.Profiles.profile_metrics_timeline(person_id, since=since, count=count, sort=sort)\n```\n\n\n\n\n#### [Update Profile](https://developers.klaviyo.com/en/reference/update-profile)\n\n```python\nclient.Profiles.update_profile(person_id, params=params)\n```\n\n\n\n## Templates\n\n\n#### [Clone Template](https://developers.klaviyo.com/en/reference/clone-template)\n\n```python\nclient.Templates.clone_template(template_id, name=name)\n```\n\n\n\n\n#### [Create New Template](https://developers.klaviyo.com/en/reference/create-template)\n\n```python\nclient.Templates.create_template(name=name, html=html)\n```\n\n\n\n\n#### [Delete Template](https://developers.klaviyo.com/en/reference/delete-template)\n\n```python\nclient.Templates.delete_template(template_id)\n```\n\n\n\n\n#### [Get All Templates](https://developers.klaviyo.com/en/reference/get-templates)\n\n```python\nclient.Templates.get_templates(page=page, count=count)\n```\n\n\n\n\n#### [Render Template](https://developers.klaviyo.com/en/reference/render-template)\n\n```python\nclient.Templates.render_template(template_id, context=context)\n```\n\n\n\n\n#### [Render and Send Template](https://developers.klaviyo.com/en/reference/send-template)\n\n```python\nclient.Templates.send_template(template_id, from_email=from_email, from_name=from_name, subject=subject, to=to, context=context)\n```\n\n\n\n\n#### [Update Template](https://developers.klaviyo.com/en/reference/update-template)\n\n```python\nclient.Templates.update_template(template_id, name=name, html=html)\n```\n\n\n\n## TrackIdentify\n\n\n#### [Identify Profile (Legacy)](https://developers.klaviyo.com/en/reference/identify-get)\n\n```python\nclient.TrackIdentify.identify_get(data)\n```\n\n\n\n\n#### [Identify Profile](https://developers.klaviyo.com/en/reference/identify-post)\n\n```python\nclient.TrackIdentify.identify_post(data=data)\n```\n\n\n\n\n#### [Track Profile Activity (Legacy)](https://developers.klaviyo.com/en/reference/track-get)\n\n```python\nclient.TrackIdentify.track_get(data)\n```\n\n\n\n\n#### [Track Profile Activity](https://developers.klaviyo.com/en/reference/track-post)\n\n```python\nclient.TrackIdentify.track_post(data=data)\n```\n\n\n\n# Appendix\n\n## Limitations\n\n- The `api_key` is set at the global level: this means that if you manage multiple stores, you will need to run the code for each store in a different environment \n\n## Refresher on catching exceptions:\n\n```python\ntry:\n    YOUR_CALL\nexcept Exception as e:\n    print(e.status)\n    print(e.reason)\n    print(e.body)\n    print(e.headers)\n```\n\n## Namespace\n\nIn the interest of making the SDK Pythonic, we made the following namespace changes *relative* to the language agnostic resources up top.\n\n1. dashes `-` become underscores `_`\n2. all other non-alphanumeric symbols, including spaces, are removed.\n\nFor example:\n* `get-campaigns` becomes `get_campaigns`\n* `Track \u0026 Identify` becomes `TrackIdentify`\n\n## Parameters \u0026 Arguments\n\nThe parameters follow the same naming conventions as the resource groups and operations.\n\nWe stick to the following convention for parameters/arguments\n\n1. All parameters are passed as function args.\n2. All optional params, as well as all Body and Form Data params (including required ones), are passed as keyword args.\n3. All query and path params that are tagged as `required` in the docs are passed as positional args.\n4. There is no need to pass in your private `api_key` for any operations, as it is defined upon client instantiation; public key is still required where.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklaviyo%2Fklaviyo-python-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklaviyo%2Fklaviyo-python-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklaviyo%2Fklaviyo-python-sdk/lists"}