Tarantool CE/EE Documentation portal logo
Support
Updated at July 17, 2026   02:08 PM

Module uuid

Overview

A "UUID" is a Universally unique identifier. If an application requires that a value be unique only within a single computer or on a single database, then a simple counter is better than a UUID, because getting a UUID is time-consuming (it requires a syscall). For clusters of computers, or widely distributed applications, UUIDs are better. Tarantool generates UUIDs following the rules for RFC 4122 version 4 variant 1.

API Reference

Below is list of all uuid functions and members.

Name

Use

uuid.NULL

A nil UUID object

uuid()
uuid.bin()
uuid.str()

Get a UUID

uuid.new()

Create a UUID

uuid.fromstr()
uuid.frombin()
uuid_object:bin()
uuid_object:str()

Get a converted UUID

uuid.is_uuid()

Check if the specified value has UUID type

uuid_object:isnil()

Check if a UUID is an all-zero value

NULL

A nil UUID object. Contains the all-zero UUID value – 00000000-0000-0000-0000-000000000000.

new()

Since version 2.4.1. Create a UUID sequence. You can use it in an index over a UUID field. For example, to create such index for a space named test, say:

tarantool> box.space.test:create_index("pk", {parts={{field = 1, type = 'uuid'}}})
Example

Now you can insert UUIDs into the space:

tarantool> box.space.test:insert{uuid.new()}---- [e631fdcc-0e8a-4d2f-83fd-b0ce6762b13f]...tarantool> box.space.test:insert{uuid.fromstr('64d22e4d-ac92-4a23-899a-e59f34af5479')}---- [64d22e4d-ac92-4a23-899a-e59f34af5479]...tarantool> box.space.test:select{}---- - [64d22e4d-ac92-4a23-899a-e59f34af5479]- [e631fdcc-0e8a-4d2f-83fd-b0ce6762b13f]...

Returns

a UUID

Return type

cdata

__call()

Returns

a UUID

Return type

cdata

bin([byte-order])

Parameters:

  • byte-order (string) — Byte order of the resulting UUID:

  • 'l' – little-endian

  • 'b' – big-endian

  • 'h', 'host' – endianness depends on host (default)

  • 'n', 'network' – endianness depends on network

Returns

a UUID

Return type

16-byte string

str()

Returns

a UUID

Return type

36-byte binary string

fromstr(uuid-str)

Parameters:

  • uuid-str (string) — UUID in 36-byte hexadecimal string

Returns

converted UUID

Return type

cdata

frombin(uuid-bin [, byte-order])

Parameters:

  • uuid-bin (string) — UUID in 16-byte binary string

  • byte-order (string) — Byte order of the given string:

  • 'l' – little-endian,

  • 'b' – big-endian,

  • 'h', 'host' – endianness depends on host (default),

  • 'n', 'network' – endianness depends on network.

Returns

converted UUID

Return type

cdata

is_uuid(value)

Since version 2.6.1.

  • value — a value to check

Returns

true if the specified value is a UUID, and false otherwise

Return type

bool

: uuid_object

bin([byte-order])

  • byte-order (string) — Byte order of the resulting UUID:

  • 'l' – little-endian,

  • 'b' – big-endian,

  • 'h', 'host' – endianness depends on host (default),

  • 'n', 'network' – endianness depends on network.

Returns

UUID converted from cdata input value.

Return type

16-byte binary string

str()

Returns

UUID converted from cdata input value.

Return type

36-byte hexadecimal string

isnil()

The all-zero UUID value can be expressed as uuid.NULL, or as uuid.fromstr('00000000-0000-0000-0000-000000000000'). The comparison with an all-zero value can also be expressed as uuid_with_type_cdata == uuid.NULL.

Returns

true if the value is all zero, otherwise false.

Return type

bool

Example

tarantool> uuid = require('uuid')---...tarantool> uuid(), uuid.bin(), uuid.str()---- 16ffedc8-cbae-4f93-a05e-349f3ab70baa- !!binary FvG+Vy1MfUC6kIyeM81DYw==- 67c999d2-5dce-4e58-be16-ac1bcb93160f...tarantool> uu = uuid()---...tarantool> #uu:bin(), #uu:str(), type(uu), uu:isnil()---- 16- 36- cdata- false...