Render valbridge IR into Pydantic v2 models
Project description
Pydantic v2 adapter for valbridge -- generates native Pydantic BaseModel classes for valbridge's Zod/Pydantic conversion pipeline.
Installation
pip install valbridge-pydantic pydantic
# or
uv add valbridge-pydantic pydantic
Verified against pydantic 2.12.5.
Usage
This adapter is invoked by the valbridge CLI. It is typically used when converting from Zod or other valbridge-supported schema sources into Pydantic models:
// user.valbridge.jsonc
{
"$schema": "https://github.com/vectorfy-co/valbridge/schemas/python.jsonc",
"schemas": [
{
"id": "User",
"adapter": "vectorfyco/valbridge-pydantic",
"sourceType": "file",
"source": "./schemas/user.json"
}
]
}
Then generate:
valbridge generate
Use the generated models with the valbridge runtime client.
Verification
Run from the adapter directory (python/packages/adapters/pydantic/):
# JSON Schema Test Suite compliance (requires Go CLI)
cd ../../cli && go build -o valbridge . && \
./valbridge compliance --lang python --adapter-path ../python/packages/adapters/pydantic
# Unit tests
uv run pytest
# Type checking
uv run pyright src/
Fallback typing guardrails
The adapter uses Annotated[Any, BeforeValidator(...)] only for constructs where the validated domain is unbounded. Every other construct must produce a narrower type.
Allowed Any fallbacks
| Construct | Reason |
|---|---|
not |
Negation is "everything except X" -- no union can express this |
conditional (single branch) |
Unmatched values pass through unconstrained |
typeGuarded (heterogeneous) |
Unmatched types pass through the guard |
| Open tuple | Extra elements beyond prefix items are untyped |
| Recursive refs | Self-referencing $ref cycles |
Constructs that must NOT use Any
oneOf-- must produceT1 | T2 | ...conditional(if/then/else) -- must produceThenType | ElseType- Closed tuples -- must produce
tuple[T1, T2, ...] const/enum-- must produce the narrowest applicable typeallOf(object merges) -- must produce a BaseModel subclass
Disallowed patterns
- Unknown IR node kind -- must raise
ConversionError - Unresolved external refs -- must raise
ConversionError - New renderer branches must not silently return
Anywithout documented justification
Troubleshooting
- pyright errors -- adapter source must pass
uv run pyright src/with zero errors - Compliance failures -- run full compliance and compare against baseline; check that validator lambdas are functionally identical
Related packages
| Package | Purpose |
|---|---|
valbridge |
Runtime client for generated validators |
valbridge-core |
Core IR and JSON Schema parser |
valbridge-pydantic-bridge |
Bridge helpers for Pydantic generation |
@vectorfyco/valbridge-zod |
TypeScript equivalent (Zod adapter) |
Learn more
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
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 valbridge_pydantic-1.1.0.tar.gz.
File metadata
- Download URL: valbridge_pydantic-1.1.0.tar.gz
- Upload date:
- Size: 61.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d20eaae36aee4fdd62a4f50a4320e0b5b6b3378845e5895576c463879b081829
|
|
| MD5 |
afd28de82f6a9713d340d802b8f55ac0
|
|
| BLAKE2b-256 |
b9e53d2193dc8264a0be8f924527a6761af4c8855279aa9ac3c6325c285423e5
|
Provenance
The following attestation bundles were made for valbridge_pydantic-1.1.0.tar.gz:
Publisher:
release-please.yml on vectorfy-co/valbridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
valbridge_pydantic-1.1.0.tar.gz -
Subject digest:
d20eaae36aee4fdd62a4f50a4320e0b5b6b3378845e5895576c463879b081829 - Sigstore transparency entry: 1267909430
- Sigstore integration time:
-
Permalink:
vectorfy-co/valbridge@931f5c801a86a074651ae1b35443fcf44b02eff9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vectorfy-co
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@931f5c801a86a074651ae1b35443fcf44b02eff9 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file valbridge_pydantic-1.1.0-py3-none-any.whl.
File metadata
- Download URL: valbridge_pydantic-1.1.0-py3-none-any.whl
- Upload date:
- Size: 36.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7916256cf78ed836ad1403708ed40f035186dca39f45531315fbfbac98c3b996
|
|
| MD5 |
cd87ed8250860ee6fa82621e0404e4d1
|
|
| BLAKE2b-256 |
685770683c055364c90b82cb6d29d9b952164c6531ff4e6fe5658982cf2ad909
|
Provenance
The following attestation bundles were made for valbridge_pydantic-1.1.0-py3-none-any.whl:
Publisher:
release-please.yml on vectorfy-co/valbridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
valbridge_pydantic-1.1.0-py3-none-any.whl -
Subject digest:
7916256cf78ed836ad1403708ed40f035186dca39f45531315fbfbac98c3b996 - Sigstore transparency entry: 1267909514
- Sigstore integration time:
-
Permalink:
vectorfy-co/valbridge@931f5c801a86a074651ae1b35443fcf44b02eff9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vectorfy-co
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@931f5c801a86a074651ae1b35443fcf44b02eff9 -
Trigger Event:
workflow_run
-
Statement type: