2026-01-25 01:47:47 +00:00
<!DOCTYPE html>
<!-- retoor <retoor@molodetz.nl> -->
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title > uuid - Wren-CLI Manual</ title >
< link rel = "stylesheet" href = "../css/style.css" >
</ head >
< body >
< button class = "mobile-menu-toggle" > Menu</ button >
< div class = "container" >
< aside class = "sidebar" >
< div class = "sidebar-header" >
< h1 >< a href = "../index.html" > Wren-CLI</ a ></ h1 >
< div class = "version" > v0.4.0</ div >
</ div >
< nav class = "sidebar-nav" >
< div class = "section" >
< span class = "section-title" > Getting Started</ span >
< ul >
< li >< a href = "../getting-started/index.html" > Overview</ a ></ li >
< li >< a href = "../getting-started/installation.html" > Installation</ a ></ li >
< li >< a href = "../getting-started/first-script.html" > First Script</ a ></ li >
< li >< a href = "../getting-started/repl.html" > Using the REPL</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > Language</ span >
< ul >
< li >< a href = "../language/index.html" > Syntax Overview</ a ></ li >
< li >< a href = "../language/classes.html" > Classes</ a ></ li >
< li >< a href = "../language/methods.html" > Methods</ a ></ li >
< li >< a href = "../language/control-flow.html" > Control Flow</ a ></ li >
< li >< a href = "../language/fibers.html" > Fibers</ a ></ li >
< li >< a href = "../language/modules.html" > Modules</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > API Reference</ span >
< ul >
< li >< a href = "index.html" > Overview</ a ></ li >
2026-01-25 03:58:39 +00:00
< li >< a href = "string.html" > String</ a ></ li >
< li >< a href = "number.html" > Num</ a ></ li >
2026-01-25 01:47:47 +00:00
< li >< a href = "http.html" > http</ a ></ li >
< li >< a href = "websocket.html" > websocket</ a ></ li >
< li >< a href = "tls.html" > tls</ a ></ li >
< li >< a href = "net.html" > net</ a ></ li >
< li >< a href = "dns.html" > dns</ a ></ li >
< li >< a href = "json.html" > json</ a ></ li >
< li >< a href = "base64.html" > base64</ a ></ li >
< li >< a href = "regex.html" > regex</ a ></ li >
< li >< a href = "jinja.html" > jinja</ a ></ li >
< li >< a href = "crypto.html" > crypto</ a ></ li >
< li >< a href = "os.html" > os</ a ></ li >
< li >< a href = "env.html" > env</ a ></ li >
< li >< a href = "signal.html" > signal</ a ></ li >
< li >< a href = "subprocess.html" > subprocess</ a ></ li >
< li >< a href = "sqlite.html" > sqlite</ a ></ li >
< li >< a href = "datetime.html" > datetime</ a ></ li >
< li >< a href = "timer.html" > timer</ a ></ li >
< li >< a href = "io.html" > io</ a ></ li >
2026-01-25 03:58:39 +00:00
< li >< a href = "pathlib.html" > pathlib</ a ></ li >
2026-01-25 01:47:47 +00:00
< li >< a href = "scheduler.html" > scheduler</ a ></ li >
< li >< a href = "math.html" > math</ a ></ li >
< li >< a href = "uuid.html" class = "active" > uuid</ a ></ li >
< li >< a href = "html.html" > html</ a ></ li >
< li >< a href = "argparse.html" > argparse</ a ></ li >
< li >< a href = "wdantic.html" > wdantic</ a ></ li >
< li >< a href = "dataset.html" > dataset</ a ></ li >
< li >< a href = "markdown.html" > markdown</ a ></ li >
< li >< a href = "web.html" > web</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > Tutorials</ span >
< ul >
< li >< a href = "../tutorials/index.html" > Tutorial List</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > How-To Guides</ span >
< ul >
< li >< a href = "../howto/index.html" > How-To List</ a ></ li >
</ ul >
</ div >
</ nav >
</ aside >
< main class = "content" >
< nav class = "breadcrumb" >
< a href = "../index.html" > Home</ a >
< span class = "separator" > /</ span >
< a href = "index.html" > API Reference</ a >
< span class = "separator" > /</ span >
< span > uuid</ span >
</ nav >
< article >
< h1 > uuid</ h1 >
< p > The < code > uuid</ code > module provides UUID (Universally Unique Identifier) generation and validation. It supports version 4 UUIDs which are randomly generated.</ p >
< pre >< code > import "uuid" for Uuid</ code ></ pre >
< h2 > Uuid Class</ h2 >
< div class = "class-header" >
< h3 > Uuid</ h3 >
< p > UUID generation and validation</ p >
</ div >
< h3 > Static Methods</ h3 >
< div class = "method-signature" >
< span class = "method-name" > Uuid.v4</ span > () → < span class = "type" > String</ span >
</ div >
< p > Generates a new random version 4 UUID.</ p >
< ul class = "param-list" >
< li >< span class = "returns" > Returns:</ span > A 36-character UUID string in the format < code > xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx</ code ></ li >
</ ul >
< pre >< code > var id = Uuid.v4()
System.print(id) // e.g., "550e8400-e29b-41d4-a716-446655440000"</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > Uuid.isValid</ span > (< span class = "param" > string</ span > ) → < span class = "type" > Bool</ span >
</ div >
< p > Checks if a string is a valid UUID format (any version).</ p >
< ul class = "param-list" >
< li >< span class = "param-name" > string</ span > < span class = "param-type" > (String)</ span > - The string to validate</ li >
< li >< span class = "returns" > Returns:</ span > < code > true</ code > if the string is a valid UUID format, < code > false</ code > otherwise</ li >
</ ul >
< pre >< code > System.print(Uuid.isValid("550e8400-e29b-41d4-a716-446655440000")) // true
System.print(Uuid.isValid("not-a-uuid")) // false
System.print(Uuid.isValid("550e8400e29b41d4a716446655440000")) // false (missing hyphens)</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > Uuid.isV4</ span > (< span class = "param" > string</ span > ) → < span class = "type" > Bool</ span >
</ div >
< p > Checks if a string is a valid version 4 UUID.</ p >
< ul class = "param-list" >
< li >< span class = "param-name" > string</ span > < span class = "param-type" > (String)</ span > - The string to validate</ li >
< li >< span class = "returns" > Returns:</ span > < code > true</ code > if the string is a valid v4 UUID, < code > false</ code > otherwise</ li >
</ ul >
< pre >< code > var id = Uuid.v4()
System.print(Uuid.isV4(id)) // true
System.print(Uuid.isV4("550e8400-e29b-11d4-a716-446655440000")) // false (version 1)</ code ></ pre >
< h2 > UUID Format</ h2 >
< p > UUIDs are 128-bit identifiers represented as 32 hexadecimal characters separated by hyphens into five groups:</ p >
< pre >< code > xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
8 4 4 4 12 = 32 hex chars + 4 hyphens = 36 chars</ code ></ pre >
< table >
< tr >
< th > Position</ th >
< th > Description</ th >
</ tr >
< tr >
< td > M</ td >
< td > Version number (4 for v4 UUIDs)</ td >
</ tr >
< tr >
< td > N</ td >
< td > Variant (8, 9, a, or b for RFC 4122 UUIDs)</ td >
</ tr >
</ table >
< h2 > Examples</ h2 >
< h3 > Generating Unique Identifiers</ h3 >
< pre >< code > import "uuid" for Uuid
var userId = Uuid.v4()
var sessionId = Uuid.v4()
System.print("User ID: %(userId)")
System.print("Session ID: %(sessionId)")</ code ></ pre >
< h3 > Validating User Input</ h3 >
< pre >< code > import "uuid" for Uuid
var input = "550e8400-e29b-41d4-a716-446655440000"
if (Uuid.isValid(input)) {
System.print("Valid UUID")
if (Uuid.isV4(input)) {
System.print("This is a v4 UUID")
}
} else {
System.print("Invalid UUID format")
}</ code ></ pre >
< h3 > Using with Database Records</ h3 >
< pre >< code > import "uuid" for Uuid
class User {
construct new(name) {
_id = Uuid.v4()
_name = name
}
id { _id }
name { _name }
}
var user = User.new("Alice")
System.print("Created user %(user.name) with ID %(user.id)")</ code ></ pre >
< div class = "admonition note" >
< div class = "admonition-title" > Note</ div >
< p > Version 4 UUIDs are generated using cryptographically secure random bytes from the < code > crypto</ code > module. The probability of generating duplicate UUIDs is astronomically low.</ p >
</ div >
</ article >
< footer class = "page-footer" >
< a href = "math.html" class = "prev" > math</ a >
< a href = "html.html" class = "next" > html</ a >
</ footer >
</ main >
</ div >
< script src = "../js/main.js" ></ script >
</ body >
</ html >