Skip to main content

Convert json text back into proper Pydantic models.

Simple Example

from pydantic_decoder import DecoderModel, encode, decode


class MyModel(DecoderModel):
    first_name: str
    last_name: str


model = MyModel(first_name='John', last_name='Doe')
msg = model.json()
m = model.decode(msg)
assert m == model
assert isinstance(m, MyModel)

Registration Examples

Use your current models by only changing the inheritance from pydantic.BaseModel to pydantic_decoder.DecoderModel.

from pydantic_decoder import DecoderModel, register_model, encode, decode

class MyModel(DecoderModel):
    first_name: str
    last_name: str

class MyModel2(DecoderModel):
    first_name: str
    last_name: str


# Subclasses of the DecoderModel are registered automatically
# register_model(MyModel)
# register_model('Model2', MyModel2)

model = MyModel(first_name='John', last_name='Doe')
msg = encode(model)
m = decode(msg)
assert m == model
assert isinstance(m, MyModel)

model2 = MyModel2(first_name='John', last_name='Doe')
msg = encode(model2)
m2 = decode(msg)
assert m2 == model2
assert isinstance(m2, MyModel2)

Metadata

Release files for pydantic-decoder 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-decoder 1.0.2
File Size Uploaded
pydantic_decoder-1.0.2.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-decoder 1.0.2
File Interpreter ABI Platform
pydantic_decoder-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / pydantic_decoder-1.0.2.tar.gz

Download URL pydantic_decoder-1.0.2.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
146d455fc805900f4f26a0a462e6503b45840abe60128445eab58c8be5649ae3
BLAKE2b-256 checksum
How to use checksums
bfef5975aac397a9998a31fb07ff8622c57942ca61e9f4c4df8913c674ad3fe9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.8

Release files / pydantic_decoder-1.0.2-py3-none-any.whl

Download URL pydantic_decoder-1.0.2-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b25539b9d78e547b97008781788f29757b80f86d1e3cd055736f4e7dc4792887
BLAKE2b-256 checksum
How to use checksums
3e2b820955541e56f7d027da36035abef216d0ba8625252d2353f5bfc9358c2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.8

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page