SDKs overview

Dicebear Avatars offers software development kits (SDKs) and libraries designed to facilitate the programmatic generation and management of customizable avatar images. The core offering is an official JavaScript library, which enables developers to integrate avatar creation directly into client-side web applications and server-side Node.js environments. This library abstracts the underlying avatar generation logic, providing functions to specify avatar styles, seeds, and other customization options.

Beyond the official JavaScript SDK, the Dicebear ecosystem includes a range of community-contributed libraries. These community efforts extend Dicebear's reach to various other programming languages, including PHP, Python, Ruby, Go, Java, and C#. This broad language support allows developers working in diverse tech stacks to utilize Dicebear Avatars without relying solely on the HTTP API. The official Dicebear documentation portal provides detailed guides and examples for both the JavaScript library and the HTTP API, supporting straightforward integration.

Official SDKs by language

Dicebear Avatars provides an officially maintained SDK primarily for JavaScript environments. This library is designed for both browser-based and Node.js applications, offering a direct way to generate avatars without external API calls if the necessary assets are bundled or fetched appropriately. The official JavaScript library is actively developed and receives regular updates to support new avatar styles and features.

Language Package Name Installation Command Maturity
JavaScript / TypeScript @dicebear/core, @dicebear/collection npm install @dicebear/core @dicebear/collection or yarn add @dicebear/core @dicebear/collection Stable, Actively Maintained

The @dicebear/core package provides the foundational logic for avatar generation, while @dicebear/collection contains various avatar styles. Developers can choose to install specific style packages (e.g., @dicebear/adventurer) instead of the entire collection to optimize bundle size, as detailed in the Dicebear getting started guide.

Installation

Installing the Dicebear Avatars JavaScript SDK typically involves using a package manager like npm or yarn. The process is standard for modern JavaScript projects.

Prerequisites

  • Node.js and npm/yarn installed. For Node.js installation instructions, refer to the official Node.js downloads page.
  • A JavaScript or TypeScript project environment.

Installation Steps

  1. Open your project's terminal: Navigate to the root directory of your JavaScript or TypeScript project.
  2. Install the core library and desired styles: Use npm or yarn to add the necessary Dicebear packages. You will typically need @dicebear/core and at least one style package (e.g., @dicebear/initials).
npm install @dicebear/core @dicebear/initials
# OR
yarn add @dicebear/core @dicebear/initials

This command installs the core Dicebear functionality and the 'Initials' avatar style. You can install multiple style packages based on your project requirements. For a complete list of available styles and their respective packages, consult the Dicebear styles documentation.

Quickstart example

This example demonstrates how to generate an avatar using the official Dicebear JavaScript library and display it in a web application. The process involves importing the necessary modules, defining avatar options, and rendering the SVG output.

JavaScript Quickstart (Browser/Node.js)

This snippet shows how to generate an 'Initials' avatar based on a seed and retrieve its SVG string, which can then be embedded into an HTML document or saved as a file.

import { createAvatar } from '@dicebear/core';
import { initials } from '@dicebear/collection';

// Define a unique seed for the avatar generation
const seed = 'John Doe';

// Configure avatar options (optional)
const avatarOptions = {
  seed: seed,
  radius: 50,
  backgroundColor: ['#c0aede', '#b6e3f4', '#ffd5dc'],
  size: 128,
};

// Generate the avatar SVG
const avatarSvg = createAvatar(initials, avatarOptions).toSvg();

// Example for displaying in a web browser:
// Assuming you have an HTML element like <div id="avatar-container"></div>
// document.getElementById('avatar-container').innerHTML = avatarSvg;

console.log(avatarSvg);

In a web browser environment, the generated avatarSvg string can be directly injected into the DOM. For Node.js, the SVG string can be written to a file or served via an API endpoint. The createAvatar function is the central entry point, accepting an avatar style module and an options object. The toSvg() method then serializes the avatar into an SVG string. More advanced usage, including custom options and different styles, is covered in the Dicebear getting started guide.

Community libraries

While Dicebear primarily offers an official JavaScript SDK, the community has developed libraries and wrappers for various other programming languages. These community contributions enable developers to interact with the Dicebear HTTP API or, in some cases, integrate local avatar generation logic within their preferred language environments. These libraries often simplify HTTP requests to the Dicebear HTTP API endpoint and handle response parsing.

Examples of community-supported languages include:

  • PHP: Libraries exist to generate Dicebear avatars within PHP applications, often by constructing the correct API URL or using local generation logic.
  • Python: Python wrappers provide functions to easily request avatars from the Dicebear API, suitable for backend services or data generation scripts.
  • Ruby: Ruby gems are available for integrating Dicebear avatars into Ruby on Rails or other Ruby-based projects.
  • Go: Go packages allow developers to fetch and utilize Dicebear avatars in Go applications.
  • Java: Community libraries facilitate avatar generation within Java environments, often leveraging HTTP client libraries to interact with the Dicebear API.
  • C#: C# wrappers enable .NET developers to integrate Dicebear avatar functionality into their applications.
  • TypeScript: While the core library is JavaScript, it is written in TypeScript, providing excellent type definitions and strong support for TypeScript projects out of the box.

Developers interested in these community libraries should consult the Dicebear integrations page for links to specific repositories and usage instructions. The maturity and maintenance status of community libraries can vary, so it is recommended to review their documentation and support actively.