Skip to main content

Structured UUID pattern library with encode/decode support

Project description

fraiseql-uuid

UUID v4 compliant pattern with encoded metadata for the FraiseQL ecosystem.

Quality Gate codecov Python 3.12+ License: MIT

Status: โœ… v0.1.0 Production-Ready | ๐Ÿ”’ Type-Safe (ty strict) | ๐Ÿ“‹ SBOM Available

Installation

pip install fraiseql-uuid

Quick Start

from fraiseql_uuid import Pattern, UUIDGenerator

# Create pattern
pattern = Pattern()

# Generate UUID
gen = UUIDGenerator(pattern, table_code="012345")
uuid = gen.generate(instance=1)
print(uuid)  # โ†’ "01234521-0000-4000-8000-000000000001"

# Decode UUID
decoded = pattern.decode(uuid)
print(decoded["table_code"])  # โ†’ "012345"
print(decoded["instance"])    # โ†’ 1

UUID Format

Code notation: {table:6}{type:2}-{func:4}-4{scen:3}-8{scen:1}{test:2}-{inst:12} Docs notation: TTTTTTDD-FFFF-4SSS-8STT-IIIIIIIIIIII

Components

Symbol Component Length Default Description
T table_code 6 - Table/Entity code (required)
D seed_dir 2 21 Seed directory (21=general, 22=mutation, 23=query)
F function 4 0 Function code
4 version 1 4 UUID v4 version bit (fixed)
S scenario 4 0 Test scenario (split 3+1 for v4 compliance)
8 variant 1 8 UUID variant bit (fixed)
T test_case 2 0 Test case number
I instance 12 - Instance number (required)

Example

01234521-0042-4100-8015-000000000001
โ”‚      โ”‚ โ”‚  โ”‚ โ”‚  โ”‚ โ”‚  โ”‚ โ””โ”€ instance: 1
โ”‚      โ”‚ โ”‚  โ”‚ โ”‚  โ”‚ โ””โ”€โ”€โ”€ test_case: 15
โ”‚      โ”‚ โ”‚  โ”‚ โ”‚  โ””โ”€โ”€โ”€โ”€โ”€ scenario: 1000 (split as 100 + 0)
โ”‚      โ”‚ โ”‚  โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ variant: 8
โ”‚      โ”‚ โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ version: 4
โ”‚      โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ function: 42
โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ table: 012345
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ seed_dir: 21

Usage Examples

Basic Generation

from fraiseql_uuid import Pattern

pattern = Pattern()

# Minimal - uses defaults
uuid = pattern.generate(table_code="012345", instance=1)
# โ†’ "01234521-0000-4000-8000-000000000001"

# Full parameters
uuid = pattern.generate(
    table_code="123456",
    seed_dir=22,        # mutation tests
    function=42,
    scenario=1000,
    test_case=5,
    instance=999
)
# โ†’ "12345622-0042-4100-8005-000000000999"

Batch Generation

from fraiseql_uuid import Pattern, UUIDGenerator

pattern = Pattern()
gen = UUIDGenerator(pattern, table_code="012345", scenario=1000)

# Generate batch
uuids = gen.generate_batch(count=5)
# โ†’ ["01234521-0000-4100-8000-000000000001",
#    "01234521-0000-4100-8000-000000000002",
#    ...]

Decoding

from fraiseql_uuid import Pattern

pattern = Pattern()
decoded = pattern.decode("01234521-0042-4100-8015-000000000001")

print(decoded["table_code"])  # โ†’ "012345"
print(decoded["seed_dir"])    # โ†’ 21
print(decoded["function"])    # โ†’ 42
print(decoded["scenario"])    # โ†’ 1000
print(decoded["test_case"])   # โ†’ 15
print(decoded["instance"])    # โ†’ 1

Validation

from fraiseql_uuid import Pattern, UUIDValidator

pattern = Pattern()
validator = UUIDValidator(pattern)

result = validator.validate("01234521-0000-4000-8000-000000000001")
print(result.valid)  # โ†’ True

result = validator.validate("not-a-uuid")
print(result.valid)  # โ†’ False
print(result.error)  # โ†’ "Invalid UUID format: not-a-uuid"

Caching

from fraiseql_uuid import UUIDCache

cache = UUIDCache()

# Store generated UUIDs
cache.set("users", instance=1, uuid="01234521-0000-4000-8000-000000000001")
cache.set("users", instance=2, uuid="01234521-0000-4000-8000-000000000002")

# Retrieve from cache
uuid = cache.get("users", instance=1)
print(uuid)  # โ†’ "01234521-0000-4000-8000-000000000001"

CLI Usage

# Generate UUID
fraiseql-uuid generate --table 012345 --instance 1

# Generate batch
fraiseql-uuid generate --table 012345 --count 10

# Decode UUID
fraiseql-uuid decode 01234521-0000-4000-8000-000000000001

# Validate UUID
fraiseql-uuid validate 01234521-0000-4000-8000-000000000001

UUID v4 Compliance

All generated UUIDs are UUID v4 compliant:

  • Version bit 4 in the correct position
  • Variant bit 8 in the correct position
  • Can be used anywhere standard UUIDs are expected
  • Compatible with database UUID columns
  • Parseable by standard UUID libraries
import uuid

# Works with standard UUID library
generated = pattern.generate(table_code="012345", instance=1)
parsed = uuid.UUID(generated)
print(parsed.version)  # โ†’ 4
print(parsed.variant)  # โ†’ uuid.RFC_4122

Development

# Install for development
git clone https://github.com/fraiseql/fraiseql-seed
cd fraiseql-seed
uv sync

# Run tests
uv run pytest packages/fraiseql-uuid/tests -v

# Type check
uv run ty check packages/fraiseql-uuid/src

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fraiseql_uuid-0.1.1.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fraiseql_uuid-0.1.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file fraiseql_uuid-0.1.1.tar.gz.

File metadata

  • Download URL: fraiseql_uuid-0.1.1.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fraiseql_uuid-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ad931a302f11c407ed8e0d60a0459c6790e3f8a124632b77531ddc7da3e8e818
MD5 eff92f954e4c4e207dc7496b9a7df572
BLAKE2b-256 e100967634a385650b987f89c8ff5b21eae0dbd68246231015cd25fbcadbd61e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fraiseql_uuid-0.1.1.tar.gz:

Publisher: deploy.yml on fraiseql/fraiseql-seed

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fraiseql_uuid-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fraiseql_uuid-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fraiseql_uuid-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30c5399f6db7ca02813ff3358200f791db0c6ab98681c8cd74a4c581025310d0
MD5 2af60a81601bb94dadf167ba0de835a3
BLAKE2b-256 38b4d26dec72b68f357688270969f1caf8c700095fd8d3ef87b9d7ab090bd330

See more details on using hashes here.

Provenance

The following attestation bundles were made for fraiseql_uuid-0.1.1-py3-none-any.whl:

Publisher: deploy.yml on fraiseql/fraiseql-seed

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page