Tiny trait + adapter toolkit for pydantic models
Project description
pydapter
pydapter is a micro-library that lets any Pydantic model become adaptable to / from arbitrary external representations (JSON, CSV, vector stores, databases …).
from pydapter import Adaptable
from pydapter.adapters import JsonAdapter
from pydantic import BaseModel
class User(Adaptable, BaseModel):
name: str
age: int
User.register_adapter(JsonAdapter)
u = User(name="Alice", age=30)
raw = u.adapt_to(obj_key="json")
u2 = User.adapt_from(raw, obj_key="json")
assert u == u2
The library ships with a tiny core and optional extra adapters you can drop in only when you need them.
Features
- Simple API: Just mix in
Adaptableand register adapters - Extensible: Create your own adapters for any data source
- Type-safe: Leverages Pydantic's validation system
- Async support: Works with async data sources via
AsyncAdaptable - Robust error handling: Comprehensive exception hierarchy for clear error messages
Error Handling
pydapter provides a robust error handling system with a comprehensive exception hierarchy:
try:
user = User.adapt_from(invalid_data, obj_key="json")
except pydapter.exceptions.ParseError as e:
print(f"Failed to parse JSON: {e}")
except pydapter.exceptions.ValidationError as e:
print(f"Validation failed: {e}")
except pydapter.exceptions.AdapterError as e:
print(f"Other adapter error: {e}")
See Error Handling Documentation for more details.
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 pydapter-0.1.0.tar.gz.
File metadata
- Download URL: pydapter-0.1.0.tar.gz
- Upload date:
- Size: 264.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dea6521b9aa5679ca0f5b523260fb6e8e1587745ee1c06650d9ab779c37cd421
|
|
| MD5 |
2c2b811ecad5a30be439136bb6239a1c
|
|
| BLAKE2b-256 |
f99a5f11ff99e993e2dd7564ef58b71cd69b1aaec577686b23dac3a018bbacb1
|
File details
Details for the file pydapter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydapter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a114df4793876585045ad14f2336ac80745abcce167620dd40c4d10f25dd5539
|
|
| MD5 |
53729e219e3c7ece588c86f966e72008
|
|
| BLAKE2b-256 |
3989be06a42757704415d195ac880dee617a7721dd357da9680561a7fc8c2804
|