Skip to main content

@dicebear/schema

JSON Schema definitions for DiceBear avatar styles and options.

Schemas

This package exports two JSON Schemas (Draft 07):

definition.json

Validates avatar style definitions: the files that describe how a DiceBear avatar style is structured. A definition includes:

  • canvas (required): The SVG canvas dimensions and root element tree
  • components: Named, reusable SVG components with variants. At render time, a PRNG selects one variant per component. Components can also be declared as aliases of another component via extends, producing an independently-randomized instance.
  • colors: Named color palettes. Colors can define constraints such as notEqualTo (must differ from another color) or contrastTo (picks the highest-contrast value).
  • attributes: Global SVG attributes applied to the root <svg> element
  • meta: License, creator, and source metadata

Only a safe subset of SVG elements and attributes is permitted. Event handlers, external URL references, and CSS injection patterns are explicitly blocked.

Additional documentation

https://www.dicebear.com/specification/definition-schema/

options.json

Validates the options object passed by users when generating an avatar. Supported properties include:

Property Type Description
seed string PRNG seed for reproducible avatars
size integer Output size in pixels (1 to 4096)
title string Accessible title rendered as <title> and aria-label
flip string | array Mirror direction: none, horizontal, vertical, or both
scale number | [min, max] Scaling factor (0 to 10, 1 = original size)
rotate number | [min, max] Rotation in degrees (−360 to 360)
translateX number | [min, max] Horizontal offset (−1000 to 1000)
translateY number | [min, max] Vertical offset (−1000 to 1000)
borderRadius number | [min, max] Corner radius (0 = sharp, 50 = circle)
idRandomization boolean SVG ID randomization to avoid conflicts
fontFamily string | array Font family for text rendering
fontWeight integer | array Font weight (1 to 1000)
*Probability number Component display probability (0 to 100)
*Variant string | string[] | object Component variant filter and weights
*Color string | array Hex colors
*ColorFill string | array Color fill: solid, linear, or radial
*ColorFillStops integer | [min, max] Gradient color stops (min 2)
*ColorAngle number | [min, max] Gradient angle (−360 to 360)

When an option accepts an array, the PRNG either picks from the list (for discrete values) or picks a value within the range (for numeric min/max pairs).

Usage

JavaScript

npm install @dicebear/schema
import definitionSchema from "@dicebear/schema/definition.json" with { type: "json" };
import optionsSchema from "@dicebear/schema/options.json" with { type: "json" };

PHP

composer require dicebear/schema
$basePath = \Composer\InstalledVersions::getInstallPath('dicebear/schema');

$definition = json_decode(file_get_contents($basePath . '/src/definition.json'), true);
$options    = json_decode(file_get_contents($basePath . '/src/options.json'), true);

Python

pip install dicebear-schema
import json
from importlib.resources import files

definition = json.loads(files("dicebear_schema").joinpath("definition.json").read_text("utf-8"))
options    = json.loads(files("dicebear_schema").joinpath("options.json").read_text("utf-8"))

Rust

cargo add dicebear-schema

The schemas are embedded at compile time and exposed as raw JSON (&'static str). Parse them with serde_json and validate with the jsonschema crate:

use dicebear_schema::{DEFINITION, OPTIONS};

let definition: serde_json::Value = serde_json::from_str(DEFINITION)?;
let options: serde_json::Value = serde_json::from_str(OPTIONS)?;

// Or look one up by name (None if unknown); all() lists the names:
let schema = dicebear_schema::get("definition");
let all = dicebear_schema::all();

Go

go get github.com/dicebear/schema

The schemas are embedded at compile time and exposed as raw JSON (string). Parse them with encoding/json and validate with a library such as jsonschema:

import (
	"encoding/json"

	"github.com/dicebear/schema"
)

var definition map[string]any
_ = json.Unmarshal([]byte(schema.Definition), &definition)

var options map[string]any
_ = json.Unmarshal([]byte(schema.Options), &options)

// Or look one up by name (ok is false if unknown); All() lists the names:
raw, ok := schema.Get("definition")
all := schema.All()

Dart

dart pub add dicebear_schema

The schemas are embedded as Dart string constants. Parse them with dart:convert and validate with a package such as json_schema:

import 'dart:convert';

import 'package:dicebear_schema/dicebear_schema.dart' as schema;

final definitionSchema = jsonDecode(schema.definition);
final optionsSchema = jsonDecode(schema.options);

// Or look one up by name (null if unknown); `all` lists the names:
final raw = schema.get('definition');
final names = schema.all;

C#

dotnet add package DiceBear.Schema

The schemas are embedded in the assembly and exposed as raw JSON (string). Parse them with System.Text.Json and validate with a library such as JsonSchema.Net:

using System.Text.Json.Nodes;

var definitionSchema = JsonNode.Parse(DiceBear.Schema.Definition);
var optionsSchema = JsonNode.Parse(DiceBear.Schema.Options);

// Or look one up by name (null if unknown). All() lists the names:
var raw = DiceBear.Schema.Get("definition");
var names = DiceBear.Schema.All();

CDN

The schemas are available directly via CDN, so no installation is required. We recommend using a specific version to ensure stability:

https://cdn.hopjs.net/npm/@dicebear/schema@1.5.1/dist/definition.min.json
https://cdn.hopjs.net/npm/@dicebear/schema@1.5.1/dist/options.min.json

Contributing

See CONTRIBUTING.md for local development, testing, and the release process.

Sponsors

Advertisement: Many thanks to our sponsors who provide us with free or discounted products.

bunny.net

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dicebear_schema-1.5.1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dicebear_schema-1.5.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file dicebear_schema-1.5.1.tar.gz.

File metadata

  • Download URL: dicebear_schema-1.5.1.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for dicebear_schema-1.5.1.tar.gz
Algorithm Hash digest
SHA256 9f55aa09d8a82effc7787abd38b15bb5d14a94e958118355dbab8ad2fba77b3d
MD5 86a34ec38f8bc1ee41ffd5531ecbfb48
BLAKE2b-256 1fbfbafda2885897b8722821d081abcae10468187c20d6a3659d552bb15034a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for dicebear_schema-1.5.1.tar.gz:

Publisher: publish.yml on dicebear/schema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dicebear_schema-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: dicebear_schema-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for dicebear_schema-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 50eb94978b83fdeee844d1b8bb1c8efd37d295ffc009a7ad9a9c44425a4797c0
MD5 3051099ace075996de245205e0894228
BLAKE2b-256 456c40efb2f6dfbe2fb013c996ff4519271554a36b5fc9cf9be49bac47dc4549

See more details on using hashes here.

Provenance

The following attestation bundles were made for dicebear_schema-1.5.1-py3-none-any.whl:

Publisher: publish.yml on dicebear/schema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.6.1

2 files

1.6.0

2 files

This release

1.5.1 This release

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page