marshmallow-code / marshmallow-code/flask-marshmallow

Usage with Flask factory pattern?

Open
#74 7 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs help wanted
Dominant language
Python
Stars
887
Forks
65
Avg merge
7h 25m
Merged PRs (30d)
3

Description

I wasn't able to find this in the docs, but what is the recommended way to use this library with the Flask factory pattern?

My approach was to initialize the Marshmallow object in my models file and then in `register_extensions` call `Marshmallow.init_app` like so:

```python
# models.py
from flask_marshmallow import Marshmallow
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
ma = Marshmallow()
```

```python
def register_extensions(app: Flask):
db.init_app(app)
with app.app_context():
db.create_all()
db.session.commit()
ma.init_app(app)
```

Is this the recommended approach? It seems to work while trying it out from the flask shell.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the factory-pattern example in the issue, especially models.py and register_extensions. Check the existing Flask integration documentation and comment thread first; done means the recommended initialization approach is decided and documented with a clear factory-pattern example.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python, sqlalchemy
Domain
backend, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.