marshmallow-code / marshmallow-code/marshmallow

Conveniently generating schema from a nested dict

Open
#1,759 2 comments 0 reactions 0 assignees View on GitHub
feedback welcome
Dominant language
Python
Stars
7.2k
Forks
738
Avg merge
1d 23h
Merged PRs (30d)
7

Description

I'm trying to use marshmallow to validate configuration files and I would like to know how to conveniently generate nested schemas using a dictionary.

Right now, this is the only method I could think of:

```python
def nest(obj):
return fields.Nested(Schema.from_dict(obj))

defaults = {
"path": nest(
{
"file": fields.Str(),
"more_file": fields.Str(),
}
),
"cred": nest(
{
"user": fields.Str(),
"pass": fields.Str(),
}
),
}

config = json.load(config_path)
schema = Schema.from_dict(defaults)()
schema.load(config)

```
But it's very inconvenient. Is there a better method that I'm not aware of?

Contributor guide

Open the contributing guide

Research direction

Start with the Schema.from_dict and fields.Nested entry points shown in the example, and inspect how nested dictionaries are currently represented. Done means establishing a supported, more convenient way to generate nested schemas and confirming that it validates the configuration structure shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.