Ricky Moony and Lucy, a moon shaped mascot for Dream with the star shaped mascot for Gleam, each with cute cartoon eyes and a smile

Comprehensive UUID library for Gleam


Hex Package Latest Release HexDocs Coverage MIT License Gleam

What is Dream UUID?

Dream UUID gives your app UUIDs it can count on. New ones sort in the order you made them, so your tables stay fast and your records stay in order. It accepts every valid UUID it’s handed, including the rare kinds other systems sometimes produce, and gives it back exactly as it came. And it runs the same on the server and in the browser.

Features

Make IDs

Every version in the standard, with the right one a call away. Read more.

FeatureWhat you get
🕒 Time-ordered IDsv7 IDs that sort in the order you made them, across every process on the node
🎲 Random IDsv4 from the system’s secure random source
🏷️ Same name, same IDv3 and v5, with the four standard namespaces built in
🧩 Your own layoutv8 for custom bits, and v1 and v6 for systems that still use them

Read and print IDs

Text in any case, the URN form, and errors that say what’s wrong. Read more.

FeatureWhat you get
🔤 Any caseReads uppercase, lowercase and mixed text, and prints lowercase
🔗 URN formReads and prints urn:uuid: text
🧭 Exact errorsA parse error names the wrong length, or the character and where it is
💾 Every UUIDAny 16 bytes are a UUID, and they come back unchanged

Look inside an ID

The fields the standard defines, read straight from the bits. Read more.

FeatureWhat you get
⏱️ When it was madeThe time of v1, v6 and v7 IDs, ready for gleam/time
🔍 Version and layoutThe version and the variant of any UUID
🛠️ Built from fieldsMake a UUID from its time, clock sequence, node or random parts

Runs anywhere

The same API wherever Gleam runs. Read more.

FeatureWhat you get
🌐 Erlang and JavaScriptThe same API on the BEAM, Node.js, Deno, Bun and browsers
🤝 Works with youidConvert to and from youid’s Uuid without losing a bit
📦 No dependenciesThe Gleam standard library and nothing else

A Quick Example

Make an ID and read one Tested snippet Guide: Using Dream UUID

import dream_uuid.{type ParseError, type Uuid, from_string, to_string, v7}

/// A new ID for a row, as text. Each new ID sorts after the one before it.
pub fn new_id() -> String {
  v7() |> to_string
}

/// The ID in a request path, or why the text is not a UUID.
pub fn read_id(text: String) -> Result(Uuid, ParseError) {
  from_string(text)
}

Run this: new_id() → a lowercase v7 ID such as "019378a2-5c1e-7d3b-9f20-4a6e8c1b2d3f", and the next call sorts after it.

Installation

gleam add dream_uuid

Guides

Requirements

About Dream

Dream is a collection of Gleam packages for building production web applications. Each package implements its standards completely, shares the same naming and style as the others, and is fully tested. TrustBound builds Dream for its own production systems and shares it in the hope that it helps yours.

Dream UUID works on its own. You don’t need the rest of Dream to use it.

Contributing

See CONTRIBUTING.md.

License

MIT

✨ Search Document