Skip to content

Commit

Permalink
Document Schema.from_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria committed Aug 11, 2019
1 parent a3bb4a1 commit cc2d4a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -8,6 +8,7 @@ Features:

- Optimize ``List(Nested(...))`` (:issue:`779`).
- Minor performance improvements and cleanup (:pr:`1328`).
- Add ``Schema.from_dict`` (:issue:`1312`).

Deprecations/Removals:

Expand Down
18 changes: 16 additions & 2 deletions docs/quickstart.rst
Expand Up @@ -41,6 +41,20 @@ Create a schema by defining a class with variables mapping attribute names to :c

For a full reference on the available field classes, see the :ref:`API Docs <api_fields>`.

Creating Schemas From Dictionaries
----------------------------------

You can create a schema from a dictionary of fields using the `from_dict <marshmallow.Schema.from_dict>` method.

.. code-block:: python
from marshmallow import Schema, fields
UserSchema = Schema.from_dict(
{"name": fields.Str(), "email": fields.Email(), "created_at": fields.DateTime()}
)
`from_dict <marshmallow.Schema.from_dict>` is especially useful for generating schemas at runtime.

Serializing Objects ("Dumping")
-------------------------------
Expand Down Expand Up @@ -96,8 +110,8 @@ with a dictionary of validation errors, which we'll :ref:`revisit later <validat
user_data = {
"created_at": "2014-08-11T05:26:03.869245",
"email": u"ken@yahoo.com",
"name": u"Ken",
"email": "ken@yahoo.com",
"name": "Ken",
}
schema = UserSchema()
result = schema.load(user_data)
Expand Down

0 comments on commit cc2d4a1

Please sign in to comment.