Skip to main content

Tiny trait + adapter toolkit for pydantic models

Project description

pydapter

CI codecov

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 Adaptable and 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


Download files

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

Source Distribution

pydapter-0.1.0.tar.gz (264.6 kB view details)

Uploaded Source

Built Distribution

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

pydapter-0.1.0-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

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

Hashes for pydapter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dea6521b9aa5679ca0f5b523260fb6e8e1587745ee1c06650d9ab779c37cd421
MD5 2c2b811ecad5a30be439136bb6239a1c
BLAKE2b-256 f99a5f11ff99e993e2dd7564ef58b71cd69b1aaec577686b23dac3a018bbacb1

See more details on using hashes here.

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

Hashes for pydapter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a114df4793876585045ad14f2336ac80745abcce167620dd40c4d10f25dd5539
MD5 53729e219e3c7ece588c86f966e72008
BLAKE2b-256 3989be06a42757704415d195ac880dee617a7721dd357da9680561a7fc8c2804

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