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 stringreturn_uuid_object: If True, returns auuid.UUIDobject 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flex_uuid_python-0.1.1.tar.gz.
File metadata
- Download URL: flex_uuid_python-0.1.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f669e1bd11f53804ff89e37e112cd64509e8668e627cdeda5a162066fbc7aaf2
|
|
| MD5 |
254621bf95074c86c5a1cd0bb012df41
|
|
| BLAKE2b-256 |
2e00a755c87d920e89b624cae44425f8c62e2e6cdcad4c86c3cfc25c4afc9641
|
File details
Details for the file flex_uuid_python-0.1.1-py3-none-any.whl.
File metadata
- Download URL: flex_uuid_python-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
255f71e94b3afb6165ac80663eba04f20b42f65410ca5621d4e4ab608d3bc54b
|
|
| MD5 |
3da710df141835442e6007c90fa921a6
|
|
| BLAKE2b-256 |
4edb77d64076ea031cd13b7b1d1802903f1fd4ad1310a4799549d67863543fd5
|