Skip to main content

Flexible UUID parsing, normalization, and SQLAlchemy integration

Project description

flex-uuid

Flexible and safe UUID parsing and normalization utility. Whether the input is a string, 16-byte binary, or a uuid.UUID, it is processed through a single consistent flow. SQLAlchemy type integration is also provided.

Installation

pip install flex-uuid

Quick Start

from flex_uuid import UUIDStorage

# Accepts any input form
s1 = UUIDStorage("8b1a9953-c461-4af7-9bdf-66e2c0f3e2f1")
s2 = UUIDStorage("8b1a9953c4614af79bdf66e2c0f3e2f1")  # 32-hex without hyphens
s3 = UUIDStorage(s1.bytes)  # 16 bytes

assert s1.bytes == s2.bytes == s3.bytes
assert s1.uuid == s2.uuid

# Retrieve in the shape you want
print(s1.to_str())      # 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
print(s1.bytes)         # b"\x.." * 16

SQLAlchemy Integration

from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from flex_uuid import UUIDFlexType

class Base(DeclarativeBase):
    pass

class User(Base):
    __tablename__ = "users"
    id: Mapped[str] = mapped_column(UUIDFlexType(store_as_bytes=True), primary_key=True)

# When binding, str/bytes/uuid.UUID are all accepted.
# The database stores 16-byte binary. By default, reads return a string.

Options

  • store_as_bytes: If True, stores in DB as 16 bytes; if False, stores as string
  • return_uuid_object: If True, returns a uuid.UUID object on read

Why flex-uuid

  • Automatically detects various input formats: with/without hyphens, case, bytes(16), uuid.UUID
  • Consistent internal representation: always normalize to 16 bytes, then convert as needed
  • SQLAlchemy type provided: safely maps to BINARY(16)/BYTEA, etc.
  • Complete type hints, clear exception messages

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

flex_uuid_python-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

flex_uuid_python-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file flex_uuid_python-0.1.0.tar.gz.

File metadata

  • Download URL: flex_uuid_python-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for flex_uuid_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 01a046713bf985b5da81d54966c3e99e06d8a735d2eb23509ac0414179e40439
MD5 3a2f06a74aa8bbff22f061e8da501abd
BLAKE2b-256 42131501b16326b366e6624c84c049d854ade6be25d46cd7a8483a939be7e25d

See more details on using hashes here.

File details

Details for the file flex_uuid_python-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flex_uuid_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64b0fdd882cd5994f491f62e9ff5ae6cab948c7ebc6fba5cb5cbf245b7c85c0a
MD5 99dea4447c42fa621cf63709afbddf23
BLAKE2b-256 1beba9b6d05b820dedb63c6f45180908223ab7bc5de83df7ff545690047ba574

See more details on using hashes here.

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