I would like to propose adding a UUID module to the Elixir standard library.
MotivationUUIDs are a widely adopted standard for generating unique identifiers in distributed systems, currently defined in
RFC 9562 (which supersedes
RFC 4122).
In Elixir, UUID functionality is available through external libraries such as Ecto or third-party packages, but there is no standardized, dependency-free implementation in the core language.
While UUID generation can be implemented using :crypto and existing libraries, there is currently no canonical, versioned, and officially supported implementation in Elixir itself, leading to divergence in behavior across ecosystem libraries.
This leads to:
- Fragmentation in APIs across the ecosystem
- Inconsistent implementations and behavior
- Additional dependencies for a fundamental primitive
- Reimplementation of a well-defined and stable standard
Current State
Common approaches include:
- Ecto.UUID (requires Ecto dependency)
- elixir-uuid, uniq (third-party implementations)
These solutions are functional but introduce coupling and API inconsistency across projects.
Prior Art
UUID support is included in many standard libraries:
Proposed Scope
A minimal UUID module in Elixir standard library:
Core functionality
- UUID generation (v4, v7)
- Parsing and validation
- String/binary conversion
Proposed API
# Generate UUIDs
UUID.generate() # Defaults to v4 (random)
UUID.generate(:v4) # Explicit version 4
UUID.generate(:v7) # Version 7 (time-ordered, sortable)
# Parse and format
{:ok, uuid} = UUID.parse("550e8400-e29b-41d4-a716-446655440000")
{:error, :invalid_format} = UUID.parse("not-a-uuid")
UUID.to_string(uuid) # "550e8400-e29b-41d4-a716-446655440000"
UUID.to_string(uuid, :urn) # "urn:uuid:550e8400-e29b-41d4-a716-446655440000"
# Validation
UUID.valid?("550e8400-e29b-41d4-a716-446655440000") # true
UUID.valid?("invalid") # false
# Version and variant inspection
UUID.version(uuid) # Returns version number (4, 7, etc.)UUID.variant(uuid) # Returns :rfc4122
Version support
- v4 (random): primary and most widely used case
- v7 (time-ordered): recommended for modern distributed systems and database indexing
- v1 (optional / deferred): due to privacy implications (MAC address exposure)
- v3/v5 (optional): could be considered based on community demand
Implementation Notes- Expected to rely on Erlang :crypto for randomness
- No external dependencies
- Pure stdlib implementation with stable API guarantees
Benefits- Standardization across Elixir ecosystem
- Reduced dependency overhead for common use cases
- Improved interoperability between libraries and services
- Better support for modern identifier patterns (especially UUIDv7)
- Alignment with other mainstream languages
ConclusionGiven the ubiquity of UUIDs in modern systems, a standard UUID module in Elixir would provide a small but meaningful improvement to developer experience and ecosystem consistency without introducing significant complexity.
Thank you for considering this proposal.
Best regards,
Mohsen Nasiri