Skip to main content
Latest version Travis-CI

PynamoDB integration with the marshmallow (de)serialization library.

Installation

From PyPi:

$ pip install marshmallow-pynamodb

From GitHub:

$ pip install git+https://github.com/mathewmarcus/marshmallow-pynamodb#egg=marshmallow_pynamodb

Declare your models

from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute

class User(Model):
    class Meta:
        table_name = "user"
    email = UnicodeAttribute(null=True)
    first_name = UnicodeAttribute(range_key=True)
    last_name = UnicodeAttribute(hash_key=True)

Generate marshmallow schemas

from marshmallow_pynamodb import ModelSchema

class UserSchema(ModelSchema):
    class Meta:
        model = User

user_schema = UserSchema()

(De)serialize your data

user = User(last_name="Smith", first_name="John")

user_schema.dump(user).data
# {u'first_name': u'John', u'last_name': u'Smith', u'email': None}

user_schema.load({"last_name": "Smith", "first_name": "John"}).data
# user<Smith>

Nested models? No problem

from marshmallow_pynamodb.schema import ModelSchema

from pynamodb.models import Model
from pynamodb.attributes import ListAttribute, MapAttribute, NumberAttribute, UnicodeAttribute

class Location(MapAttribute):
    latitude = NumberAttribute()
    longitude = NumberAttribute()
    name = UnicodeAttribute()


class Person(MapAttribute):
    firstName = UnicodeAttribute()
    lastName = UnicodeAttribute()
    age = NumberAttribute()


class OfficeEmployeeMap(MapAttribute):
    office_employee_id = NumberAttribute()
    person = Person()
    office_location = Location()


class Office(Model):
    class Meta:
        table_name = 'OfficeModel'

    office_id = NumberAttribute(hash_key=True)
    address = Location()
    employees = ListAttribute(of=OfficeEmployeeMap)


class OfficeSchema(ModelSchema):
    class Meta:
        model = Office


OfficeSchema().load({'office_id': 789,
                     'address': {'latitude': 6.98454,
                                 'longitude': 172.38832,
                                 'name': 'some_location'},
                     'employees': [{'office_employee_id': 123,
                                    'person': {'firstName': 'John',
                                               'lastName': 'Smith',
                                               'age': 45},
                                    'office_location': {'latitude': -24.0853,
                                                        'longitude': 144.87660,
                                                        'name': 'other_location'}},
                                   {'office_employee_id': 456,
                                    'person': {'firstName': 'Jane',
                                               'lastName': 'Doe',
                                               'age': 33},
                                    'office_location': {'latitude': -20.57989,
                                                        'longitude': 92.30463,
                                                        'name': 'yal'}}]}).data
# Office<789>

License

MIT licensed. See the bundled LICENSE file for more details.

Metadata

Release files for marshmallow-pynamodb 0.8.0

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

Source distribution (sdist)

Source distribution for marshmallow-pynamodb 0.8.0
File Size Uploaded Provenance
marshmallow-pynamodb-0.8.0.tar.gz 5.5 kB Without provenance Details

Release files / marshmallow-pynamodb-0.8.0.tar.gz

Download URL marshmallow-pynamodb-0.8.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a0115e7192a00f2968c1dac69857e85916058eb27a12ae8442facb4417e3280a
BLAKE2b-256 checksum
How to use checksums
093ec91cc57452d2153785500a87fb552cdfd61c658b76d9a210350e830fe07a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for marshmallow-pynamodb 0.8.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.

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