Foundational data types and schemas for scalable Python wrappers.
Project description
py_wraps_data_types
A lightweight, foundational Python package providing core data structures and extended types for wrapper ecosystems.
Currently, this package provides the Variant type: a highly optimized, "duck-typed" Enum designed to reduce boilerplate when validating raw strings at API boundaries.
Python: 3.9+ | PyPI: py-wraps-data-types
Installation
pip install py_wraps_data_types
# or
uv add py_wraps_data_types
Features
Variant — Duck-Typed Enum
Standard Python Enum classes require explicit instantiation (e.g. MyEnum("value")), which causes friction when parsing raw strings from LLM outputs, JSON payloads, or external APIs.
The Variant class extends str and Enum to allow raw strings to seamlessly pass isinstance() checks, backed by O(1) dictionary lookups for high-performance validation.
| Feature | Description |
|---|---|
| String mixin | Inherits all standard string methods (.lower(), .startswith(), …) |
| Duck-typed validation | Raw strings matching an Enum value pass isinstance() checks |
| Clean serialization | str() returns the plain value, not EnumName.MEMBER |
| No dependencies | Zero runtime dependencies |
Usage
Define your constraints by subclassing Variant:
from py_wraps_data_types.variant import Variant
class BedrockModel(Variant):
CLAUDE_3_SONNET = "anthropic.claude-3-sonnet-20240229-v1:0"
CLAUDE_3_HAIKU = "anthropic.claude-3-haiku-20240307-v1:0"
TITAN_EMBEDDINGS = "amazon.titan-embed-text-v2:0"
class DistanceMetric(Variant):
COSINE = "cosine"
L2 = "l2"
DOT = "dot"
Use isinstance() directly against raw strings — no pre-casting required:
def query_vector_db(metric: str):
if not isinstance(metric, DistanceMetric):
raise ValueError(f"Unsupported metric. Must be one of: {list(DistanceMetric)}")
# ... execution logic ...
# Works with an enum member
query_vector_db(DistanceMetric.COSINE)
# Works with a raw string from a JSON payload
query_vector_db("cosine")
String methods work naturally
model = BedrockModel.CLAUDE_3_SONNET
model.startswith("anthropic") # True
model.upper() # "ANTHROPIC.CLAUDE-3-SONNET-20240229-V1:0"
"claude" in model # True
Clean serialization
status = DistanceMetric.COSINE
str(status) # "cosine" (not "DistanceMetric.COSINE")
f"{status}" # "cosine"
repr(status) # "<DistanceMetric.COSINE: 'cosine'>"
Examples
A runnable example is provided in examples/basic_usage.py:
python examples/basic_usage.py
Testing
Install dev dependencies and run the test suite with pytest:
pip install "py_wraps_data_types[dev]"
pytest
Or, from a local clone:
pip install -e ".[dev]"
pytest
The test suite covers:
- Enum member definition and access
isinstance()with raw strings (matching and non-matching)isinstance()with enum members (same class and cross-class)- Non-string inputs (int, None, list, dict)
- Inherited string methods
__str__serialization- Equality comparisons
- End-to-end validation function pattern
Requirements
- Python 3.9 or later
- No runtime dependencies
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 py_wraps_data_types-0.1.2.tar.gz.
File metadata
- Download URL: py_wraps_data_types-0.1.2.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ac68a4ce1621df00df0b805f97e6b6c911f21da40a62b7fb3758e7b292f4cc4
|
|
| MD5 |
d237a3b798d5ae8071248769d20c42da
|
|
| BLAKE2b-256 |
1cfed75c4479088c821360327e26286b038f4b39fe7e6cc1c3b2107904da0dcc
|
File details
Details for the file py_wraps_data_types-0.1.2-py3-none-any.whl.
File metadata
- Download URL: py_wraps_data_types-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddce0a4ec17e8c2c3dffd6816e896ac59af15e61256b9665b77cd1f536a879f0
|
|
| MD5 |
9930c98f393cb282d2d5c4f36dc96fb9
|
|
| BLAKE2b-256 |
dcad6652c11b4a3e3b2b06b920aa7a9fce6ea912e7d9cf0a20c9bdf43f8c81b5
|