SDKs overview
Lemon Squeezy offers several Software Development Kits (SDKs) and community-contributed libraries designed to facilitate interaction with its e-commerce and subscription management API. These SDKs abstract the underlying HTTP requests and responses, providing language-specific methods for common operations such as managing products, processing orders, and handling webhooks. The primary goal of these libraries is to reduce the boilerplate code required for integration, allowing developers to focus on application logic rather than direct API communication protocols. The Lemon Squeezy API itself is RESTful, utilizing standard HTTP methods (GET, POST, PUT, DELETE) and JSON payloads for data exchange, as detailed in the Lemon Squeezy API reference.
The availability of SDKs across multiple programming languages reflects a common industry practice to support diverse development environments. For example, similar approaches are adopted by other payment and e-commerce platforms like Stripe, which provides SDKs for various languages to simplify payment processing integrations, and PayPal, with SDKs for server-side and client-side operations. This strategy aims to lower the barrier to entry for developers who are already proficient in a specific language, enabling quicker adoption and implementation of Lemon Squeezy's features.
Official SDKs by language
Lemon Squeezy maintains official SDKs for popular server-side and client-side programming languages. These SDKs are developed and supported by the Lemon Squeezy team, ensuring compatibility with the latest API versions and features. Each SDK provides a consistent interface to the Lemon Squeezy API, mapping API endpoints to language-specific functions or methods. The table below outlines the currently available official SDKs, their respective package managers, and typical installation commands.
| Language | Package Name | Installation Command | Maturity | Source |
|---|---|---|---|---|
| PHP | lemonsqueezy/lemonsqueezy-php |
composer require lemonsqueezy/lemonsqueezy-php |
Stable | Lemon Squeezy PHP SDK documentation |
| Ruby | lemonsqueezy |
gem install lemonsqueezy |
Stable | Lemon Squeezy Ruby SDK documentation |
| Python | lemonsqueezy-python |
pip install lemonsqueezy-python |
Stable | Lemon Squeezy Python SDK documentation |
| JavaScript | @lemonsqueezy/lemonsqueezy.js |
npm install @lemonsqueezy/lemonsqueezy.js |
Stable | Lemon Squeezy JavaScript SDK documentation |
Installation
Installation of Lemon Squeezy SDKs follows standard practices for each respective programming language's ecosystem. Developers typically use package managers to add the SDK as a dependency to their project. This process automatically handles dependencies and ensures the correct version of the SDK is integrated. Detailed instructions for each SDK are available in the official Lemon Squeezy SDK documentation.
PHP SDK Installation
The PHP SDK is distributed via Composer, the dependency manager for PHP. To install, navigate to your project's root directory in the terminal and execute:
composer require lemonsqueezy/lemonsqueezy-php
After installation, Composer generates an autoload.php file, which must be included in your application to use the SDK classes.
Ruby SDK Installation
For Ruby projects, the SDK is available as a Gem. Use the Bundler gem manager or install directly:
gem install lemonsqueezy
If using Bundler in a Rails or other Ruby project, add gem 'lemonsqueezy' to your Gemfile and run bundle install.
Python SDK Installation
The Python SDK is distributed through PyPI (Python Package Index) and can be installed using pip:
pip install lemonsqueezy-python
It is recommended to install Python packages within a Python virtual environment to manage project-specific dependencies.
JavaScript SDK Installation
The JavaScript SDK is available via npm (Node Package Manager) or Yarn. For Node.js projects or front-end build systems, use:
npm install @lemonsqueezy/lemonsqueezy.js
Or with Yarn:
yarn add @lemonsqueezy/lemonsqueezy.js
This SDK can be used in both Node.js environments and modern web browsers, often requiring a bundler like Webpack or Rollup for browser usage.
Quickstart example
This example demonstrates how to use the Python SDK to retrieve a list of products from your Lemon Squeezy store. This assumes you have already installed the lemonsqueezy-python package and have your API key available. API keys can be generated and managed from your Lemon Squeezy dashboard settings.
import os
from lemonsqueezy import LemonSqueezy
# It's recommended to store your API key as an environment variable
api_key = os.environ.get("LEMONSQUEEZY_API_KEY")
if not api_key:
raise ValueError("LEMONSQUEEZY_API_KEY environment variable not set.")
ls = LemonSqueezy(api_key=api_key)
try:
# Fetch all products from your store
products_response = ls.products.all()
if products_response.success:
products = products_response.data
print(f"Successfully retrieved {len(products)} products:")
for product in products:
print(f"- Product ID: {product.id}, Name: {product.attributes.name}, Price: {product.attributes.price_formatted}")
else:
print(f"Error fetching products: {products_response.error}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
This Python snippet initializes the Lemon Squeezy client with an API key, then calls the products.all() method to fetch product data. The response is checked for success, and product details are iterated and printed. Error handling is included to catch potential issues during the API call, a crucial aspect of robust application development, as highlighted in Google Cloud's API error design guidelines.
Community libraries
Beyond the officially supported SDKs, the Lemon Squeezy developer community may contribute additional libraries, wrappers, or tools that extend functionality or provide support for other programming languages or frameworks. These community efforts are often shared on platforms like GitHub or package repositories specific to their language (e.g., Packagist for PHP, RubyGems for Ruby, PyPI for Python, npm for JavaScript). While not officially maintained by Lemon Squeezy, these libraries can offer alternative approaches or specialized integrations.
Developers seeking community-driven solutions are advised to consult the Lemon Squeezy community forums, official documentation, or perform searches on code hosting platforms. When using community-contributed libraries, it is important to review their documentation, recent update history, and community support to ensure they are well-maintained and compatible with the latest Lemon Squeezy API version. The Lemon Squeezy community page often lists or links to relevant external resources and discussions.