SDKs overview

Pantry offers a straightforward REST API for managing JSON data, primarily designed for simplicity and rapid deployment in projects requiring a lightweight, schema-less data store. While the core interaction is via direct HTTP requests, developers can opt for official or community-contributed Software Development Kits (SDKs) and libraries to streamline integration into their applications. These SDKs handle the underlying HTTP communication, serialization, and deserialization of JSON objects, allowing developers to interact with their Pantries using native language constructs. The primary benefit of using an SDK is to reduce boilerplate code and manage API interactions more efficiently, especially within larger applications or when integrating Pantry into specific development environments.

The Pantry API itself is based on standard HTTP methods (GET, POST, PUT, DELETE) and JSON payloads, making it accessible from virtually any programming language or environment capable of making web requests. This design principle allows for a broad range of community contributions, as the fundamental API contract is well-defined and widely understood. For detailed information on the API endpoints and request/response formats, developers can consult the Pantry API documentation.

Official SDKs by language

Pantry maintains official SDKs for popular programming languages, providing a supported and consistent way to interact with the service. These SDKs are typically kept up-to-date with any API changes and offer convenience methods for common operations. The official offerings focus on languages widely used in web development and scripting, aligning with Pantry's use cases for prototyping and serverless backends.

Language Package Name Installation Command Maturity
JavaScript (Node.js/Browser) pantry.js npm install pantry.js Stable
Python pantry-py pip install pantry-py Stable

These official SDKs are designed to abstract away the direct HTTP calls, allowing developers to focus on data logic rather than network communication. For instance, instead of constructing a curl command or an XMLHttpRequest, an SDK method like pantry.get('myPantryId') handles the specifics. This approach aligns with the design principles of many modern API clients, such as the Stripe Node.js client or the AWS SDK for JavaScript, which aim to simplify developer interaction with complex APIs.

Installation

Installing Pantry SDKs follows standard package management practices for their respective language ecosystems. Developers typically use command-line tools to add the SDK as a dependency to their project.

JavaScript (Node.js and Browser Environments)

The JavaScript SDK, pantry.js, is distributed via npm, the Node.js package manager. It can be used in both Node.js server-side applications and client-side browser environments, provided a module bundler like Webpack or Rollup is used for browser compatibility.

npm install pantry.js
# or using yarn
yarn add pantry.js

After installation, the library can be imported into your JavaScript files:

import Pantry from 'pantry.js'; // ES Module syntax
// const Pantry = require('pantry.js'); // CommonJS syntax

Python

The Python SDK, pantry-py, is available on PyPI, the Python Package Index. Installation is performed using pip, Python's package installer.

pip install pantry-py

Once installed, the library can be imported into your Python scripts:

from pantry import Pantry

Ensuring proper installation and dependency management is crucial for project stability. Python developers often use virtual environments to manage project-specific dependencies, preventing conflicts between different projects. This practice is detailed in the Python documentation on virtual environments.

Quickstart example

These examples demonstrate basic operations with Pantry using the official SDKs: creating a new Pantry, storing data, retrieving data, and updating data. For these examples, replace YOUR_PANTRY_ID with an actual Pantry ID from your Pantry account or a newly created one.

JavaScript Quickstart

This example shows how to use pantry.js to perform common data operations.

import Pantry from 'pantry.js';

const pantryId = 'YOUR_PANTRY_ID'; // Replace with your Pantry ID
const pantryClient = new Pantry(pantryId);

async function runPantryOperations() {
  try {
    // 1. Get all data from the Pantry
    console.log('Fetching all data...');
    const allData = await pantryClient.get();
    console.log('All data:', allData);

    // 2. Add new data to the Pantry (POST request)
    console.log('Adding new item...');
    const newItem = { id: 1, name: 'Apple', price: 1.00 };
    const postResponse = await pantryClient.post(newItem);
    console.log('Post response:', postResponse);

    // 3. Update existing data (PUT request - overwrites entire Pantry content)
    console.log('Updating Pantry content...');
    const updatedContent = { items: [{ id: 2, name: 'Banana', price: 0.75 }] };
    const putResponse = await pantryClient.put(updatedContent);
    console.log('Put response:', putResponse);

    // 4. Get specific data (GET with key/path - depends on how data is structured)
    // Pantry's simple API usually means getting the whole object and then filtering locally
    console.log('Fetching updated content...');
    const currentContent = await pantryClient.get();
    console.log('Current content after PUT:', currentContent);

    // 5. Delete the Pantry (DANGER: this deletes all data!)
    // console.log('Deleting Pantry...');
    // const deleteResponse = await pantryClient.delete();
    // console.log('Delete response:', deleteResponse);

  } catch (error) {
    console.error('Pantry operation failed:', error.message);
  }
}

runPantryOperations();

Python Quickstart

This Python example uses pantry-py to interact with a Pantry.

from pantry import Pantry

pantry_id = 'YOUR_PANTRY_ID'  # Replace with your Pantry ID
pantry_client = Pantry(pantry_id)

def run_pantry_operations():
    try:
        # 1. Get all data from the Pantry
        print('Fetching all data...')
        all_data = pantry_client.get()
        print(f'All data: {all_data}')

        # 2. Add new data to the Pantry (POST request)
        print('Adding new item...')
        new_item = {'id': 1, 'name': 'Orange', 'price': 1.20}
        post_response = pantry_client.post(new_item)
        print(f'Post response: {post_response}')

        # 3. Update existing data (PUT request - overwrites entire Pantry content)
        print('Updating Pantry content...')
        updated_content = {'products': [{'id': 3, 'name': 'Grapes', 'price': 2.50}]}
        put_response = pantry_client.put(updated_content)
        print(f'Put response: {put_response}')

        # 4. Get specific data
        print('Fetching updated content...')
        current_content = pantry_client.get()
        print(f'Current content after PUT: {current_content}')

        # 5. Delete the Pantry (DANGER: this deletes all data!)
        # print('Deleting Pantry...')
        # delete_response = pantry_client.delete()
        # print(f'Delete response: {delete_response}')

    except Exception as e:
        print(f'Pantry operation failed: {e}')

if __name__ == '__main__':
    run_pantry_operations()

Community libraries

Due to Pantry's simple RESTful API design, community members have developed libraries and wrappers in various languages. While not officially supported or maintained by Pantry, these libraries can offer solutions for specific use cases or preferred programming environments. Developers should exercise due diligence when using community-contributed code, including reviewing the source for security, reliability, and active maintenance.

Some examples of community contributions might include:

  • Go/Golang wrappers: Simple HTTP clients could be built leveraging Go's standard library net/http package to interact with Pantry endpoints.
  • PHP clients: Libraries using Guzzle or similar HTTP clients to provide an object-oriented interface for Pantry.
  • Ruby gems: Small Ruby gems that encapsulate API calls for Ruby on Rails or other Ruby applications.

Finding such libraries typically involves searching package repositories like GitHub, npm, PyPI, or Packagist for terms like "Pantry API client" or "Pantry SDK" combined with the desired language. The open nature of the web and API development encourages such contributions, similar to how many open-source projects, such as those listed on Google's Open Source projects page, foster a vibrant ecosystem of tools and integrations around core services.

Before integrating any community library, it is advisable to check:

  • Last update date: To ensure it's actively maintained.
  • Issue tracker: To gauge community support and known bugs.
  • Documentation: To understand its usage and limitations.
  • Dependencies: To avoid potential conflicts with existing project dependencies.

For direct API interaction without an SDK, developers can always fall back to standard HTTP client libraries available in their language of choice, such as fetch in JavaScript, requests in Python, or the built-in HTTP capabilities in Java or C#.