SDKs overview

Bunny.net offers a range of Software Development Kits (SDKs) and client libraries designed to facilitate interaction with its suite of services, including BunnyCDN, Bunny Stream, and Bunny Storage. These SDKs abstract the underlying RESTful API, allowing developers to integrate Bunny.net functionalities into their applications using familiar programming language constructs rather than direct HTTP requests. The primary goal of these libraries is to streamline common operations such as uploading and managing files, configuring CDN zones, and controlling video content.

The availability of official and community-contributed SDKs across various programming languages, including PHP, Node.js, Python, Go, Ruby, and C#, supports a broad developer ecosystem. This multi-language support ensures that developers can choose the most suitable library for their existing technology stacks. Each SDK typically provides methods for authentication, resource creation, retrieval, update, and deletion, aligning with the core principles of API design. For detailed information on the API endpoints and request/response structures, developers can consult the Bunny.net API reference documentation.

Using an SDK can reduce development time and potential errors by handling details such as request formatting, error handling, and response parsing. This allows developers to focus on application logic rather than the intricacies of API communication. Furthermore, SDKs often provide improved type safety and IDE auto-completion features, contributing to a more efficient and robust development process, a common benefit of client libraries across various platforms like Stripe's API client libraries.

Official SDKs by language

Bunny.net maintains official SDKs for several popular programming languages, ensuring direct support and compatibility with their latest API versions. These official libraries are typically the most reliable choice for integration, offering comprehensive coverage of API functionalities and active maintenance. The following table provides an overview of the key official SDKs:

Language Package Name Installation Command Maturity Primary Use Cases
PHP bunnycdn/bunnycdn-php composer require bunnycdn/bunnycdn-php Official CDN zone management, storage operations, stream management
Node.js @bunnycdn/api npm install @bunnycdn/api or yarn add @bunnycdn/api Official CDN zone management, storage operations, stream management
Python bunnycdn-python pip install bunnycdn-python Official CDN zone management, storage operations, stream management
Go github.com/BunnyWay/go-bunnycdn go get github.com/BunnyWay/go-bunnycdn Official CDN zone management, storage operations, stream management
C# BunnyCDN.API (NuGet) dotnet add package BunnyCDN.API Official CDN zone management, storage operations, stream management

Each of these SDKs is designed to encapsulate the HTTP communication with the Bunny.net API, providing an object-oriented or functional interface for developers. They typically handle API key authentication, request signing, and parsing of JSON responses. For instance, the PHP SDK allows developers to interact with BunnyCDN storage using methods like Storage->uploadFile(), simplifying file management tasks. The Node.js SDK, being asynchronous, integrates well into modern JavaScript environments, enabling non-blocking API calls for performance-critical applications.

Installation

Installing Bunny.net SDKs typically follows standard package management practices for each respective language. Below are detailed installation instructions for the most commonly used official SDKs:

PHP SDK Installation

The PHP SDK is distributed via Composer, the dependency manager for PHP. To install:

composer require bunnycdn/bunnycdn-php

After installation, you can include the autoloader in your project:

require 'vendor/autoload.php';

use BunnyCDN\API\BunnyCDNAPI;

$bunnyCDN = new BunnyCDNAPI('YOUR_API_KEY');
// ... use the SDK

Node.js SDK Installation

The Node.js SDK is available on npm. To install:

npm install @bunnycdn/api

Or, if you use Yarn:

yarn add @bunnycdn/api

You can then import and use it in your JavaScript or TypeScript projects:

import { BunnyCDNAPI } from '@bunnycdn/api';

const bunnyCDN = new BunnyCDNAPI('YOUR_API_KEY');
// ... use the SDK

Python SDK Installation

The Python SDK is distributed via pip, the package installer for Python. To install:

pip install bunnycdn-python

Usage in Python:

from bunnycdn import BunnyCDNAPI

bunny_cdn = BunnyCDNAPI('YOUR_API_KEY')
# ... use the SDK

Go SDK Installation

For Go projects, you can fetch the module directly:

go get github.com/BunnyWay/go-bunnycdn

Then import it in your Go code:

import (
    "github.com/BunnyWay/go-bunnycdn"
)

func main() {
    api := bunnycdn.NewBunnyCDNAPI("YOUR_API_KEY")
    // ... use the API
}

C# SDK Installation

The C# SDK is available as a NuGet package. You can install it using the .NET CLI:

dotnet add package BunnyCDN.API

Alternatively, use the NuGet Package Manager in Visual Studio. Then, in your C# code:

using BunnyCDN.API;

var client = new BunnyCDN.API.BunnyClient("YOUR_API_KEY");
// ... use the client

Quickstart example

This quickstart demonstrates how to use the Node.js SDK to list storage zones and upload a file to Bunny Storage. This example assumes you have Node.js and npm installed and have obtained your Bunny.net API key. For more detailed examples and API methods, refer to the Bunny.net Storage API documentation.

Node.js Quickstart: Listing Storage Zones and Uploading a File

import { BunnyCDNAPI } from '@bunnycdn/api';
import { readFileSync } from 'fs';

// Replace with your actual API key and Storage Zone details
const API_KEY = 'YOUR_BUNNYNET_API_KEY';
const STORAGE_ZONE_NAME = 'YourStorageZoneName'; // e.g., 'MyWebsiteAssets'
const FILE_PATH_LOCAL = './example.txt'; // Path to a local file to upload
const FILE_PATH_REMOTE = 'my-folder/example.txt'; // Desired path on Bunny Storage

const bunnyCDN = new BunnyCDNAPI(API_KEY);

async function manageStorage() {
  try {
    // 1. List all Storage Zones
    console.log('Listing Storage Zones...');
    const storageZones = await bunnyCDN.storage.listStorageZones();
    console.log('Available Storage Zones:', storageZones.map(zone => zone.Name));

    const targetStorageZone = storageZones.find(zone => zone.Name === STORAGE_ZONE_NAME);
    if (!targetStorageZone) {
      console.error(`Storage Zone '${STORAGE_ZONE_NAME}' not found.`);
      return;
    }

    const storageZoneId = targetStorageZone.Id;

    // 2. Upload a file to the specified Storage Zone
    console.log(`Uploading ${FILE_PATH_LOCAL} to ${STORAGE_ZONE_NAME}/${FILE_PATH_REMOTE}...`);
    const fileContent = readFileSync(FILE_PATH_LOCAL);
    
    // The uploadFile method requires the Storage Zone ID, the remote path, and the file content (Buffer)
    await bunnyCDN.storage.uploadFile(
      storageZoneId,
      FILE_PATH_REMOTE,
      fileContent
    );
    console.log('File uploaded successfully!');

    // 3. (Optional) List files in a specific path within the Storage Zone
    console.log(`Listing files in '${STORAGE_ZONE_NAME}/my-folder/'...`);
    const filesInFolder = await bunnyCDN.storage.listFiles(
      storageZoneId,
      'my-folder/'
    );
    console.log('Files in my-folder:', filesInFolder.map(file => file.Path + file.ObjectName));

  } catch (error) {
    console.error('An error occurred:', error.message);
    if (error.response && error.response.data) {
      console.error('API Error Details:', error.response.data);
    }
  }
}

// Create a dummy file for the example if it doesn't exist
import { writeFileSync, existsSync } from 'fs';
if (!existsSync(FILE_PATH_LOCAL)) {
  writeFileSync(FILE_PATH_LOCAL, 'This is a test file for Bunny.net SDK example.');
  console.log(`Created dummy file: ${FILE_PATH_LOCAL}`);
}

manageStorage();

To run this example:

  1. Save the code as bunny-quickstart.js.
  2. Create a file named example.txt in the same directory, or let the script create one.
  3. Replace YOUR_BUNNYNET_API_KEY with your actual Bunny.net API key.
  4. Replace YourStorageZoneName with the name of an existing Storage Zone in your Bunny.net account.
  5. Execute from your terminal: node bunny-quickstart.js

This script first retrieves a list of all storage zones associated with the provided API key. It then identifies the target storage zone by name and proceeds to upload a local file to a specified remote path within that zone. Finally, it demonstrates how to list files within a particular folder on Bunny Storage, confirming the upload. Error handling is included to catch potential API communication issues or invalid credentials.

Community libraries

Beyond the officially supported SDKs, the Bunny.net developer community has contributed various libraries and tools that extend integration possibilities. These community-maintained projects can offer specialized functionalities, alternative language support, or integrations with specific frameworks. While not officially supported by Bunny.net, they can be valuable resources for developers seeking solutions outside the core SDK offerings.

Examples of community contributions often include:

  • Framework-specific integrations: Libraries that provide wrappers or plugins for popular web frameworks like Laravel, Django, or Ruby on Rails, simplifying asset management within those environments.
  • Specialized tools: Utilities for specific tasks, such as bulk file operations, advanced CDN cache purging, or detailed logging and monitoring integrations.
  • Less common language bindings: SDKs for languages not officially covered, enabling a broader range of development environments to interact with Bunny.net services.

Developers interested in community libraries should exercise due diligence by checking the project's activity, documentation, and community support before integrating them into production environments. Platforms like GitHub are common repositories for such projects, where developers can find source code, issue trackers, and contribution guidelines. While official SDKs provide a baseline, community efforts often showcase innovative approaches and fill niche requirements, similar to how Google Maps Platform community libraries extend functionality.

To discover community-driven projects, developers can typically search GitHub or other code hosting platforms for 'Bunny.net' or 'BunnyCDN' along with their preferred programming language or framework. The Bunny.net developer community forums or Discord channels may also provide recommendations and discussions around these external contributions.