SDKs overview
Klaviyo provides a set of official Software Development Kits (SDKs) designed to facilitate integration with the Klaviyo API. These libraries encapsulate the complexities of making direct HTTP requests, handling data serialization, and managing authentication, allowing developers to interact with Klaviyo's platform using familiar language constructs. The SDKs support common operations such as managing profiles, tracking events, and working with campaigns and flows, aligning with Klaviyo's core products for email marketing, SMS marketing, and marketing automation. Developers can utilize these SDKs to synchronize customer data, trigger personalized communications, and automate marketing workflows within their applications.
In addition to the official offerings, the developer community has contributed various libraries and connectors that extend Klaviyo API support to other languages and frameworks. These community-driven projects can offer alternative integration approaches or specialized functionalities not covered by the official SDKs. When choosing an SDK or library, developers should evaluate factors such as language compatibility, maintenance status, and specific feature requirements.
Official SDKs by language
Klaviyo maintains official SDKs for widely used programming languages, providing a supported and consistent way to interact with the API. These SDKs are developed and updated by Klaviyo, ensuring compatibility with the latest API versions and features. The official SDKs abstract the underlying RESTful API endpoints, offering a more object-oriented or function-based interface for developers.
The following table outlines the official SDKs, their respective package identifiers, installation commands, and maturity status:
| Language | Package Name | Installation Command | Maturity |
|---|---|---|---|
| Python | klaviyo-sdk |
pip install klaviyo-sdk |
Stable |
| Node.js | klaviyo-sdk |
npm install klaviyo-sdk |
Stable |
| Ruby | klaviyo-sdk |
gem install klaviyo-sdk |
Stable |
Developers are encouraged to consult the Klaviyo API reference documentation for the most current information on SDK versions and capabilities.
Installation
Installing a Klaviyo SDK typically involves using the package manager specific to the chosen programming language. The installation process is designed to be straightforward, allowing developers to quickly integrate the SDK into their projects.
Python SDK installation
For Python projects, the klaviyo-sdk can be installed using pip, the standard package installer for Python, as specified in Python's official installation guide.
pip install klaviyo-sdk
After installation, the library can be imported into Python scripts:
import klaviyo_sdk
Node.js SDK installation
Node.js developers can install the klaviyo-sdk using npm, the default package manager for Node.js, following typical npm installation procedures.
npm install klaviyo-sdk
Once installed, the SDK can be required or imported into Node.js applications:
const Klaviyo = require('klaviyo-sdk');
// Or for ES Modules
import Klaviyo from 'klaviyo-sdk';
Ruby SDK installation
Ruby projects use Bundler or gem for managing dependencies. The klaviyo-sdk is available as a Ruby gem, which can be installed via the gem install command.
gem install klaviyo-sdk
Alternatively, add the following line to your Gemfile and run bundle install:
gem 'klaviyo-sdk'
Then, require the gem in your Ruby application:
require 'klaviyo_sdk'
Quickstart example
This quickstart example demonstrates how to use the Python SDK to identify a profile and track an event. This basic operation is fundamental for building customer profiles and recording key interactions within Klaviyo, which are crucial for subsequent marketing automation and segmentation.
Before running the example, ensure you have set up your Klaviyo API keys. The example uses a private API key, which should be handled securely and never exposed publicly. For detailed guidance on API keys, refer to the Klaviyo API authentication documentation.
import klaviyo_sdk
from klaviyo_sdk.rest import ApiException
from klaviyo_sdk.models import *
# Configure API key authorization:
configuration = klaviyo_sdk.Configuration(
api_key={'ApiKeyAuth': 'YOUR_KLAVIYO_PRIVATE_API_KEY'}
)
with klaviyo_sdk.ApiClient(configuration) as api_client:
# Create an instance of the Profiles API
profiles_api = klaviyo_sdk.ProfilesApi(api_client)
# Example: Create or update a profile
profile_data = ProfileCreateQuery(
data=ProfileCreateQueryData(
type=ProfileEnum("profile"),
attributes=ProfileCreateQueryResourceObjectAttributes(
email="[email protected]",
first_name="Test",
last_name="User",
phone_number="+15551234567"
)
)
)
try:
created_profile = profiles_api.create_profile(profile_data)
print("Profile created/updated successfully:")
print(created_profile.to_dict())
except ApiException as e:
print(f"Error creating profile: {e}")
# Create an instance of the Events API
events_api = klaviyo_sdk.EventsApi(api_client)
# Example: Track an event for the profile
event_data = EventCreateQuery(
data=EventCreateQueryData(
type=EventEnum("event"),
attributes=EventCreateQueryResourceObjectAttributes(
profile=EventCreateQueryResourceObjectAttributesProfile(
data=ProfileCreateQueryResourceObject(
type=ProfileEnum("profile"),
id=created_profile.data.id # Use the ID of the created/updated profile
)
),
metric=MetricCreateQueryResourceObject(
data=MetricCreateQueryResourceObjectData(
type=MetricEnum("metric"),
name="Product Purchased"
)
),
time="2026-05-29T10:00:00Z", # ISO 8601 format
value=50.00,
properties={
"product_name": "Example Product",
"category": "Electronics",
"quantity": 1
}
)
)
)
try:
tracked_event = events_api.create_event(event_data)
print("Event tracked successfully:")
print(tracked_event.to_dict())
except ApiException as e:
print(f"Error tracking event: {e}")
This code snippet initializes the API client with a private API key, then proceeds to create or update a user profile. Subsequently, it tracks a Product Purchased event associated with that profile. Replace 'YOUR_KLAVIYO_PRIVATE_API_KEY' with your actual Klaviyo private API key and adjust the profile and event data as needed for your specific use case. Remember to handle potential exceptions that may arise from API calls.
Community libraries
Beyond the official SDKs, the Klaviyo developer community has created and maintained various libraries and tools, expanding the reach of the Klaviyo API to other programming languages and frameworks. These community-driven projects can offer specialized integrations, alternative architectural patterns, or support for languages not officially covered by Klaviyo. Developers considering community libraries should review their documentation, community support, and maintenance frequency.
Examples of common types of community contributions include:
- PHP clients: For developers working with PHP-based applications or content management systems like WordPress or Magento, community wrappers might provide a more native experience.
- Go/Golang clients: For high-performance backend services, community-maintained Go libraries can enable efficient integration with Klaviyo.
- Frontend framework integrations: Libraries or components designed for specific JavaScript frameworks (e.g., React, Vue, Angular) can simplify tracking client-side events directly to Klaviyo.
- Serverless function examples: Community resources often include examples or pre-built modules for integrating Klaviyo with serverless platforms like AWS Lambda or Firebase Functions.
While official SDKs are recommended for their direct support and maintenance by Klaviyo, community libraries can be valuable for specific project requirements. Due diligence is advised to ensure compatibility, security, and ongoing support for any third-party library. Developers can often find these resources on platforms like GitHub or through developer forums. For a comprehensive list of available integrations and partners, including those built by the community, developers can explore the Klaviyo Integrations page, though direct SDK listings may require further investigation on community code repositories.