SDKs overview

Wandbox functions as an online compiler and execution environment, allowing users to test and share code snippets across a multitude of programming languages and versions directly through a web interface. While the primary interaction model is browser-based, developers can extend Wandbox's utility into local applications and scripts through its underlying API. Software Development Kits (SDKs) and client libraries serve as wrappers for this API, simplifying the process of sending code for compilation and execution, and retrieving results programmatically.

These SDKs are not traditional libraries designed for application development within a specific language, but rather client-side tools for interacting with the Wandbox service itself. They enable use cases such as:

  • Automated Testing: Integrating Wandbox into CI/CD pipelines to quickly test code against various compiler versions.
  • Educational Platforms: Embedding live code execution environments within learning management systems or tutorials.
  • IDE Integrations: Developing plugins for local IDEs to offload compilation to Wandbox.
  • Code Snippet Management: Programmatically uploading, executing, and retrieving links for shared code snippets.

The availability of SDKs is largely community-driven due to Wandbox's open-source nature. Developers contribute client libraries in various languages, leveraging the public API to replicate the functionality available on the Wandbox homepage.

Official SDKs by language

While Wandbox itself is a service, its primary interaction method for programmatic use is through its web API. The project maintains a set of community-contributed client libraries rather than a single 'official' SDK suite developed by a core team. These clients act as SDKs, providing language-specific interfaces to interact with the Wandbox API. The following table summarizes commonly used and well-maintained client libraries, which are often considered de-facto official due to their prevalence and direct support for Wandbox's features.

Language Package/Library Name Description Maturity
Python wandbox-api A Python client for interacting with the Wandbox API, supporting code submission, compiler listing, and result retrieval. Stable
Ruby wandbox-client A Ruby gem providing an interface to the Wandbox service for compiling and running code. Stable
Go go-wandbox A Go client library for the Wandbox API, enabling Go applications to send code for execution. Mature
Node.js wandbox-api-client A JavaScript client for Node.js environments to interact with the Wandbox public API. Active
Rust wandbox-rs A Rust crate offering a programmatic interface to the Wandbox online compiler. Developing

Each of these libraries abstracts the HTTP requests and JSON parsing involved in communicating with the Wandbox backend, providing idiomatic functions for operations such as listing available compilers, submitting code, and fetching output. Developers can consult the Wandbox community resources for the most up-to-date list of client libraries and their specific documentation.

Installation

Installation procedures for Wandbox client libraries follow standard package management practices for their respective programming languages. Below are examples for some of the most common languages. Ensure you have the corresponding package manager installed for your development environment.

Python

To install the wandbox-api Python client, use pip:

pip install wandbox-api

Ruby

For the Ruby wandbox-client gem, use gem:

gem install wandbox-client

Go

Go modules are used to manage dependencies. To add go-wandbox to your project:

go get github.com/your-username/go-wandbox # Replace with actual repo path if different
go mod tidy

Node.js

Install the wandbox-api-client using npm or yarn:

npm install wandbox-api-client
# OR
yarn add wandbox-api-client

Rust

Add wandbox-rs to your Cargo.toml file:

[dependencies]
wandbox-rs = "0.1.0" # Check crates.io for the latest version

Then, build your project using Cargo:

cargo build

Refer to the specific library's documentation on its GitHub repository or package manager page for detailed installation instructions and any prerequisites. For general guidance on package management, resources like the MDN Web Docs on package management can provide foundational information.

Quickstart example

This quickstart example demonstrates how to use the Python wandbox-api client to compile and run a simple C++ program. The goal is to send C++ code to Wandbox, execute it, and print the standard output received from the service.

Python Quickstart with wandbox-api

First, ensure you have the wandbox-api library installed:

pip install wandbox-api

Next, create a Python file (e.g., wandbox_test.py) with the following content:

import wandbox

# The C++ code to execute
cpp_code = """
#include <iostream>

int main() {
    std::cout << "Hello from Wandbox C++!" << std::endl;
    return 0;
}
"""

def main():
    # List available compilers (optional, for demonstration)
    # compilers = wandbox.get_compilers()
    # print(f"Available C++ compilers: {[c['name'] for c in compilers if 'cpp' in c['language']]}")

    # Define options for the compilation and execution
    options = {
        'compiler': 'clang-head', # Specify a C++ compiler (e.g., clang-head, gcc-head)
        'code': cpp_code,
        'codes': [], # Additional code files if needed
        'options': 'warning,cpp-pedantic-errors', # Compiler options
        'compiler-option-raw': '',
        'runtime-option-raw': '',
        'stdin': '',
        'save': False, # Set to True to get a permalink
        'encoding': 'UTF-8'
    }

    print("Sending code to Wandbox...")
    try:
        result = wandbox.compile(options)

        if result:
            if 'program_message' in result and result['program_message']:
                print("Program Output:")
                print(result['program_message'])
            elif 'compiler_error' in result and result['compiler_error']:
                print("Compiler Error:")
                print(result['compiler_error'])
            elif 'program_error' in result and result['program_error']:
                print("Program Error:")
                print(result['program_error'])
            else:
                print("No specific output or error message found.")

            if 'permlink' in result:
                print(f"Permalink: {result['permlink']}")
        else:
            print("No result received from Wandbox.")

    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == '__main__':
    main()

Run the script from your terminal:

python wandbox_test.py

The script will connect to the Wandbox service, send the C++ code, and print the output received. The compiler option can be changed to other available C++ compilers listed on the Wandbox website or by programmatically querying wandbox.get_compilers().

Community libraries

Beyond the commonly used client libraries, the Wandbox ecosystem benefits from a variety of community-driven tools and integrations. These resources often extend Wandbox's functionality or provide specialized interfaces for niche use cases. Because Wandbox exposes a public API, developers are free to create their own clients and integrations in any language or environment.

Examples of community contributions include:

  • Editor Plugins: Integrations for text editors like Vim or Emacs that allow sending code snippets directly to Wandbox for compilation and displaying results within the editor.
  • Discord Bots: Bots that can execute code in response to commands within a Discord server, using Wandbox as the backend compiler.
  • Browser Extensions: Tools that enhance the Wandbox web experience or provide quick access to its features from other web pages.
  • CLI Tools: Command-line interfaces that simplify sending files or piped input to Wandbox without writing a full script.
  • Language-Specific Wrappers: Client libraries in less common languages, developed by enthusiasts to integrate Wandbox into their preferred development environments.

These community projects are typically hosted on platforms like GitHub and are maintained independently. Developers interested in exploring or contributing to these efforts can search GitHub for "wandbox client" or "wandbox API" to discover a range of projects. The strength of Wandbox's community contributions is a testament to its open nature and the utility it provides to developers for quick, multi-language code execution. For general information on contributing to open-source projects, resources such as AWS documentation on open source contributions can be helpful.