pynamodb-encoder
Introduction
pynamodb-encoder provides helper classes that can convert PynamoDB Model objects into JSON serializable dict. It can also decode such dict back into those Model objects. Polymorphic models and attributes are also supported.
Examples
def test_encode_complex_model(encoder: Encoder):
class Pet(DynamicMapAttribute):
cls = DiscriminatorAttribute()
name = UnicodeAttribute()
class Cat(Pet, discriminator="Cat"):
pass
class Dog(Pet, discriminator="Dog"):
pass
class Human(Model):
name = UnicodeAttribute()
pets = ListAttribute(of=Pet)
jon = Human(name="Jon", pets=[Cat(name="Garfield", age=43), Dog(name="Odie")])
assert encoder.encode(jon) == {
"name": "Jon",
"pets": [{"cls": "Cat", "name": "Garfield", "age": 43}, {"cls": "Dog", "name": "Odie"}],
}
def test_decode_complex_model(decoder: Decoder):
class Pet(DynamicMapAttribute):
cls = DiscriminatorAttribute()
class Cat(Pet, discriminator="Cat"):
name = UnicodeAttribute()
class Dog(Pet, discriminator="Dog"):
breed = UnicodeAttribute()
class Human(Model):
name = UnicodeAttribute()
age = NumberAttribute()
pets = ListAttribute(of=Pet)
jon = decoder.decode(
Human,
{
"name": "Jon",
"age": 70,
"pets": [{"cls": "Cat", "name": "Garfield"}, {"cls": "Dog", "breed": "Terrier"}],
},
)
assert jon.name == "Jon"
assert jon.age == 70
assert isinstance(jon.pets, list)
assert len(jon.pets) == 2
assert isinstance(jon.pets[0], Cat)
assert jon.pets[0].name == "Garfield"
assert isinstance(jon.pets[1], Dog)
assert jon.pets[1].breed == "Terrier"
More examples can be found in encoder_test.py and decoder_test.py
Metadata
Release files for pynamodb-encoder 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pynamodb_encoder-0.2.0.tar.gz | 4.1 kB | Without provenance | Details for pynamodb_encoder-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pynamodb_encoder-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pynamodb_encoder-0.2.0-py3-none-any.whl |
Total release size: 10.3 kB
Release files / pynamodb_encoder-0.2.0.tar.gz
| Download URL | pynamodb_encoder-0.2.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
40d5b8b465ea51d3818eef7a8e085634b31b72edbb8cb6d9680e3c412945a2f6
|
|
BLAKE2b-256 checksum How to use checksums |
dfe3d3d8f91ce486da2a38995a5e0e6d8551c99ca6ec72673d5f22231da671e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.12.3 Linux/6.5.0-1018-azure
|
Release files / pynamodb_encoder-0.2.0-py3-none-any.whl
| Download URL | pynamodb_encoder-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b02f07586df2ff5261a6b3e8958f6a13112a68cc49ce783982c3ebcc01094fa
|
|
BLAKE2b-256 checksum How to use checksums |
9ddcfc293de0cddf24e8a71f7c08f6378f1cf0ab8c87955d9445606e539cb2ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.12.3 Linux/6.5.0-1018-azure
|
Security for pynamodb-encoder 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.