Convenient anonymous and nested schemas using dict literal syntax for Marshmallow.
Project description
Marshmallow Factory
===================
Inspired by [Voluptuous](https://github.com/alecthomas/voluptuous).
It's sometimes inconvenient to define named
[Marshmallow](https://github.com/marshmallow-code/marshmallow)
Schemas, especially when those schemas are deeply nested.
Example:
```
class InnerSchema(Schema):
inner_bool = Boolean()
class MiddleSchema(Schema):
middle_int = Integer()
middle_nested = Nested(InnerSchema)
class OuterSchema(Schema):
outer_str = String()
outer_nested = Nested(MiddleSchema)
schema_instance = OuterSchema()
schema_instance.validate(input_)
```
So, this library provides a convenient syntax for defining
deeply nested Schemas.
```
from marshmallow_factory import schema
OuterSchema = schema({
'outer_str': String(),
'outer_nested': Nested(schema({
'middle_int': Integer(),
'middle_nested': Nested(schema({
'inner_bool': Boolean()
}))
}))
})
schema_instance = OuterSchema()
schema_instance.validate(input_)
```
Support For Meta Options
------------------------
Meta options are supported using the following syntax:
```
class Meta:
strict = True # or your other options
my_schema = schema({
'Meta': Meta,
'str': String()
})
```
Alternative Syntax
------------------
Schema factory arguments can also be supplied as keyword
arguments rather than a dictionary.
```
my_schema = schema(Meta=Meta, str=String())
```
For nested Schemas, plain dictionary literals can be provided
instead of Nested(schema({...}).
```
from marshmallow_factory import schema
OuterSchema = schema({
'outer_str': String(),
'outer_nested': {
'middle_int': Integer(),
'middle_nested': {
'inner_bool': Boolean()
}
}
})
schema_instance = OuterSchema()
schema_instance.validate(input_)
```
===================
Inspired by [Voluptuous](https://github.com/alecthomas/voluptuous).
It's sometimes inconvenient to define named
[Marshmallow](https://github.com/marshmallow-code/marshmallow)
Schemas, especially when those schemas are deeply nested.
Example:
```
class InnerSchema(Schema):
inner_bool = Boolean()
class MiddleSchema(Schema):
middle_int = Integer()
middle_nested = Nested(InnerSchema)
class OuterSchema(Schema):
outer_str = String()
outer_nested = Nested(MiddleSchema)
schema_instance = OuterSchema()
schema_instance.validate(input_)
```
So, this library provides a convenient syntax for defining
deeply nested Schemas.
```
from marshmallow_factory import schema
OuterSchema = schema({
'outer_str': String(),
'outer_nested': Nested(schema({
'middle_int': Integer(),
'middle_nested': Nested(schema({
'inner_bool': Boolean()
}))
}))
})
schema_instance = OuterSchema()
schema_instance.validate(input_)
```
Support For Meta Options
------------------------
Meta options are supported using the following syntax:
```
class Meta:
strict = True # or your other options
my_schema = schema({
'Meta': Meta,
'str': String()
})
```
Alternative Syntax
------------------
Schema factory arguments can also be supplied as keyword
arguments rather than a dictionary.
```
my_schema = schema(Meta=Meta, str=String())
```
For nested Schemas, plain dictionary literals can be provided
instead of Nested(schema({...}).
```
from marshmallow_factory import schema
OuterSchema = schema({
'outer_str': String(),
'outer_nested': {
'middle_int': Integer(),
'middle_nested': {
'inner_bool': Boolean()
}
}
})
schema_instance = OuterSchema()
schema_instance.validate(input_)
```
Project details
Release history Release notifications | RSS feed
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 marshmallow_factory-0.1.0.tar.gz.
File metadata
- Download URL: marshmallow_factory-0.1.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33959508dfa0b26713b08eec4dcaace5bf02fdc5a7a38b1b0ef0ceeae519071a
|
|
| MD5 |
3c2a82e30ca1138be8157f07e8596d82
|
|
| BLAKE2b-256 |
cc975162ba4fa100fe2218e9f1d77b0b497df287dfb8fd70c9e206d8efb6bd33
|
File details
Details for the file marshmallow_factory-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: marshmallow_factory-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85e93720ec6ac310fc38abfd58cd2fb0ed18b6715cdb72562d020641984c5842
|
|
| MD5 |
1146c339a2bd45da1fa7e27cc266f3bd
|
|
| BLAKE2b-256 |
93254806405f7e053c1ed9753095716bdc316cda5976ccef62c6e841fbb8aa00
|