Skip to content

Named Binary Tag (NBT)

endstone.nbt

Classes relating to the NBT data format.

Classes:

Name Description
ByteArrayTag

An NBT tag holding an array of unsigned 8-bit integers.

ByteTag

An NBT tag holding an unsigned 8-bit integer value.

CompoundTag

A named NBT compound tag mapping string keys to tags.

DoubleTag

An NBT tag holding a 64-bit floating-point value.

FloatTag

An NBT tag holding a 32-bit floating-point value.

IntArrayTag

An NBT tag holding an array of signed 32-bit integers.

IntTag

An NBT tag holding a signed 32-bit integer value.

ListTag

An NBT list tag of homogeneously-typed tags.

LongTag

An NBT tag holding a signed 64-bit integer value.

ShortTag

An NBT tag holding a signed 16-bit integer value.

StringTag

An NBT tag holding a string value.

Tag

Base class for all NBT tag variants.

Functions:

Name Description
load

Deserialize binary NBT data into a tag.

ByteArrayTag

ByteArrayTag()
ByteArrayTag(iterable: Iterable)
ByteArrayTag(buffer: Buffer)

Bases: Tag

An NBT tag holding an array of unsigned 8-bit integers.

Methods:

Name Description
append

Appends a value to the end of this tag.

clear

Removes all values from this tag.

dump

Serialize this tag to binary NBT format.

extend

Appends all values from an iterable to the end of this tag.

append

append(value: int) -> None

Appends a value to the end of this tag.

Parameters:

Name Type Description Default
value int

The value to append.

required

clear

clear() -> None

Removes all values from this tag.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

extend

extend(iterable: Iterable) -> None

Appends all values from an iterable to the end of this tag.

Parameters:

Name Type Description Default
iterable Iterable

An iterable of values to append.

required

ByteTag

ByteTag()
ByteTag(value: int)

Bases: Tag

An NBT tag holding an unsigned 8-bit integer value.

Methods:

Name Description
dump

Serialize this tag to binary NBT format.

Attributes:

Name Type Description
value int

The underlying value of this tag.

value property

value: int

The underlying value of this tag.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

CompoundTag

CompoundTag()
CompoundTag(mapping: dict)

Bases: Tag

A named NBT compound tag mapping string keys to tags.

Methods:

Name Description
clear

Removes all entries from this compound tag.

dump

Serialize this tag to binary NBT format.

items

Returns an iterator over the (key, tag) pairs in this compound tag.

keys

Returns an iterator over the keys in this compound tag.

pop
setdefault

Returns the tag for the given key, inserting a default if the key is not present.

to_dict

Converts this compound tag to a plain Python dict of native values.

values

Returns an iterator over the tags in this compound tag.

clear

clear() -> None

Removes all entries from this compound tag.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

items

items() -> Iterator[tuple[str, Tag]]

Returns an iterator over the (key, tag) pairs in this compound tag.

keys

keys() -> Iterator[str]

Returns an iterator over the keys in this compound tag.

pop

pop(key: str) -> Tag
pop(key: str, default: object = None) -> object

setdefault

setdefault(key: str, default: Tag) -> Tag

Returns the tag for the given key, inserting a default if the key is not present.

Parameters:

Name Type Description Default
key str

The key to look up.

required
default Tag

The tag to insert and return if the key is not present.

required

Returns:

Type Description
Tag

The tag associated with the key, or the newly inserted default.

to_dict

to_dict() -> dict

Converts this compound tag to a plain Python dict of native values.

values

values() -> Iterator[Tag]

Returns an iterator over the tags in this compound tag.

DoubleTag

DoubleTag()
DoubleTag(value: float)

Bases: Tag

An NBT tag holding a 64-bit floating-point value.

Methods:

Name Description
dump

Serialize this tag to binary NBT format.

Attributes:

Name Type Description
value float

The underlying value of this tag.

value property

value: float

The underlying value of this tag.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

FloatTag

FloatTag()
FloatTag(value: float)

Bases: Tag

An NBT tag holding a 32-bit floating-point value.

Methods:

Name Description
dump

Serialize this tag to binary NBT format.

Attributes:

Name Type Description
value float

The underlying value of this tag.

value property

value: float

The underlying value of this tag.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

IntArrayTag

IntArrayTag()
IntArrayTag(iterable: Iterable)

Bases: Tag

An NBT tag holding an array of signed 32-bit integers.

Methods:

Name Description
append

Appends a value to the end of this tag.

clear

Removes all values from this tag.

dump

Serialize this tag to binary NBT format.

extend

Appends all values from an iterable to the end of this tag.

append

append(value: int) -> None

Appends a value to the end of this tag.

Parameters:

Name Type Description Default
value int

The value to append.

required

clear

clear() -> None

Removes all values from this tag.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

extend

extend(iterable: Iterable) -> None

Appends all values from an iterable to the end of this tag.

Parameters:

Name Type Description Default
iterable Iterable

An iterable of values to append.

required

IntTag

IntTag()
IntTag(value: int)

Bases: Tag

An NBT tag holding a signed 32-bit integer value.

Methods:

Name Description
dump

Serialize this tag to binary NBT format.

Attributes:

Name Type Description
value int

The underlying value of this tag.

value property

value: int

The underlying value of this tag.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

ListTag

ListTag()
ListTag(iterable: Iterable)

Bases: Tag

An NBT list tag of homogeneously-typed tags.

Methods:

Name Description
append

Appends a tag to the end of this list.

clear

Removes all tags from this list.

dump

Serialize this tag to binary NBT format.

empty

Returns True if this list contains no tags.

extend

Appends all tags from an iterable to the end of this list.

pop

Removes and returns the tag at the given index.

size

The number of tags in this list.

to_list

Converts this list to a plain Python list of native values.

append

append(tag: Tag) -> None

Appends a tag to the end of this list.

Parameters:

Name Type Description Default
tag Tag

The tag to append. It must have the same type as the existing elements.

required

clear

clear() -> None

Removes all tags from this list.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

empty

empty() -> bool

Returns True if this list contains no tags.

extend

extend(iterable: Iterable) -> None

Appends all tags from an iterable to the end of this list.

Parameters:

Name Type Description Default
iterable Iterable

An iterable of tags to append. Each tag must have the same type as the existing elements.

required

pop

pop(index: int = -1) -> Tag

Removes and returns the tag at the given index.

Parameters:

Name Type Description Default
index int

The index of the tag to remove. Defaults to the last tag.

-1

Returns:

Type Description
Tag

The removed tag.

size

size() -> int

The number of tags in this list.

to_list

to_list() -> list

Converts this list to a plain Python list of native values.

LongTag

LongTag()
LongTag(value: int)

Bases: Tag

An NBT tag holding a signed 64-bit integer value.

Methods:

Name Description
dump

Serialize this tag to binary NBT format.

Attributes:

Name Type Description
value int

The underlying value of this tag.

value property

value: int

The underlying value of this tag.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

ShortTag

ShortTag()
ShortTag(value: int)

Bases: Tag

An NBT tag holding a signed 16-bit integer value.

Methods:

Name Description
dump

Serialize this tag to binary NBT format.

Attributes:

Name Type Description
value int

The underlying value of this tag.

value property

value: int

The underlying value of this tag.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

StringTag

StringTag()
StringTag(value: str)

Bases: Tag

An NBT tag holding a string value.

Methods:

Name Description
dump

Serialize this tag to binary NBT format.

Attributes:

Name Type Description
value str

The underlying value of this tag.

value property

value: str

The underlying value of this tag.

dump

dump(
    name: str | None = None,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> bytes

Serialize this tag to binary NBT format.

Parameters:

Name Type Description Default
name str | None

Optional root tag name. If None, an empty name is used.

None
byte_order Literal['little', 'big']

Byte order for encoding, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, use Bedrock network varint encoding for lengths and Int/Long values.

False

Returns:

Name Type Description
bytes bytes

The binary NBT data.

Tag

Base class for all NBT tag variants.

load

load(
    data: bytes,
    byte_order: Literal["little", "big"] = "little",
    network: bool = False,
) -> tuple[Tag, str]

Deserialize binary NBT data into a tag.

Parameters:

Name Type Description Default
data bytes

Binary NBT data (bytes).

required
byte_order Literal['little', 'big']

Byte order of the binary data, either 'little' (Bedrock) or 'big' (Java).

'little'
network bool

If True, expect Bedrock network varint encoding.

False

Returns:

Type Description
tuple[Tag, str]

tuple[Tag, str]: A tuple of (tag, name) where name is the root tag name.