flask-marshmallow 0.12.0__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/CHANGELOG.rst +99 -3
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/CONTRIBUTING.rst +3 -3
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/LICENSE +1 -1
- flask_marshmallow-1.1.0/PKG-INFO +170 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/README.rst +12 -9
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_templates/side-primary.html +1 -1
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_templates/side-secondary.html +1 -1
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/conf.py +5 -8
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/index.rst +9 -2
- flask_marshmallow-1.1.0/pyproject.toml +66 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/src/flask_marshmallow/__init__.py +27 -17
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/src/flask_marshmallow/fields.py +109 -25
- flask_marshmallow-1.1.0/src/flask_marshmallow/py.typed +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/src/flask_marshmallow/schema.py +10 -11
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/src/flask_marshmallow/sqla.py +17 -34
- flask_marshmallow-1.1.0/src/flask_marshmallow/validate.py +183 -0
- flask_marshmallow-1.1.0/tests/__init__.py +0 -0
- flask_marshmallow-1.1.0/tests/conftest.py +112 -0
- flask_marshmallow-1.1.0/tests/test_core.py +61 -0
- flask_marshmallow-1.1.0/tests/test_fields.py +169 -0
- flask_marshmallow-1.1.0/tests/test_io.py +0 -0
- flask_marshmallow-1.1.0/tests/test_sqla.py +288 -0
- flask_marshmallow-1.1.0/tests/test_validate.py +107 -0
- flask_marshmallow-1.1.0/tox.ini +42 -0
- flask-marshmallow-0.12.0/MANIFEST.in +0 -5
- flask-marshmallow-0.12.0/PKG-INFO +0 -160
- flask-marshmallow-0.12.0/setup.cfg +0 -13
- flask-marshmallow-0.12.0/setup.py +0 -84
- flask-marshmallow-0.12.0/src/flask_marshmallow/compat.py +0 -9
- flask-marshmallow-0.12.0/src/flask_marshmallow.egg-info/PKG-INFO +0 -160
- flask-marshmallow-0.12.0/src/flask_marshmallow.egg-info/SOURCES.txt +0 -37
- flask-marshmallow-0.12.0/src/flask_marshmallow.egg-info/dependency_links.txt +0 -1
- flask-marshmallow-0.12.0/src/flask_marshmallow.egg-info/not-zip-safe +0 -1
- flask-marshmallow-0.12.0/src/flask_marshmallow.egg-info/requires.txt +0 -52
- flask-marshmallow-0.12.0/src/flask_marshmallow.egg-info/top_level.txt +0 -1
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/Makefile +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_static/logo.png +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_themes/LICENSE +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_themes/README +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_themes/flask/layout.html +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_themes/flask/relations.html +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_themes/flask/static/flasky.css_t +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_themes/flask/theme.conf +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_themes/flask_small/layout.html +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_themes/flask_small/static/flasky.css_t +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_themes/flask_small/theme.conf +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/_themes/flask_theme_support.py +7 -7
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/changelog.rst +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/license.rst +0 -0
- {flask-marshmallow-0.12.0 → flask_marshmallow-1.1.0}/docs/make.bat +0 -0
|
@@ -1,6 +1,102 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
1.1.0 (2024-01-16)
|
|
5
|
+
******************
|
|
6
|
+
|
|
7
|
+
Features:
|
|
8
|
+
|
|
9
|
+
* Add type coverage (:pr:`290`).
|
|
10
|
+
|
|
11
|
+
1.0.0 (2024-01-16)
|
|
12
|
+
******************
|
|
13
|
+
|
|
14
|
+
Features:
|
|
15
|
+
|
|
16
|
+
* Add field ``fields.File``, ``validate.FileType``, and ``validate.FileSize``
|
|
17
|
+
for deserializing uploaded files (:issue:`280`, :pr:`282`).
|
|
18
|
+
Thanks :user:`uncle-lv` for the PR
|
|
19
|
+
* Add field ``Config`` for serializing Flask configuration values (:issue:`280`, :pr:`281`).
|
|
20
|
+
Thanks :user:`greyli` for the PR.
|
|
21
|
+
|
|
22
|
+
Support:
|
|
23
|
+
|
|
24
|
+
* Support marshmallow-sqlalchemy>=0.29.0.
|
|
25
|
+
* Test against Python 3.12.
|
|
26
|
+
* Drop support for Python 3.7.
|
|
27
|
+
|
|
28
|
+
Other changes:
|
|
29
|
+
|
|
30
|
+
* *Backwards-incompatible*: Remove ```flask_marshmallow.__version__``
|
|
31
|
+
and ``flask_marshmallow.__version_info__`` attributes (:pr:`284`).
|
|
32
|
+
Use feature detection or ``importlib.metadata.version("flask-marshmallow")`` instead.
|
|
33
|
+
|
|
34
|
+
0.15.0 (2023-04-05)
|
|
35
|
+
*******************
|
|
36
|
+
|
|
37
|
+
* Changes to supported software versions.
|
|
38
|
+
|
|
39
|
+
* python3.6 or later and marshmallow>=3.0.0 are now required
|
|
40
|
+
* Add support for python3.11
|
|
41
|
+
* For ``sqlalchemy`` integration, marshmallow-sqlalchemy>=0.28.2 and
|
|
42
|
+
flask-sqlalchemy>=3.0.0 are now required
|
|
43
|
+
|
|
44
|
+
* *Backwards-incompatible*: ``URLFor`` and ``AbsoluteURLFor`` now do not accept
|
|
45
|
+
parameters for ``flask.url_for`` as top-level parameters. They must always be
|
|
46
|
+
passed in the ``values`` dictionary, as explained in the v0.14.0 changelog.
|
|
47
|
+
|
|
48
|
+
Bug fixes:
|
|
49
|
+
|
|
50
|
+
* Address distutils deprecation warning in Python 3.10 (:pr:`242`).
|
|
51
|
+
Thanks :user:`GabrielLins64` for the PR.
|
|
52
|
+
|
|
53
|
+
0.14.0 (2020-09-27)
|
|
54
|
+
*******************
|
|
55
|
+
|
|
56
|
+
* Add ``values`` argument to ``URLFor`` and ``AbsoluteURLFor`` for passing values to ``flask.url_for``.
|
|
57
|
+
This prevents unrelated parameters from getting passed (:issue:`52`, :issue:`67`).
|
|
58
|
+
Thanks :user:`AlrasheedA` for the PR.
|
|
59
|
+
|
|
60
|
+
Deprecation:
|
|
61
|
+
|
|
62
|
+
* Passing params to ``flask.url_for`` via ``URLFor``'s and ``AbsoluteURLFor``'s constructor
|
|
63
|
+
params is deprecated. Pass ``values`` instead.
|
|
64
|
+
|
|
65
|
+
.. code-block:: python
|
|
66
|
+
|
|
67
|
+
# flask-marshmallow<0.14.0
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class UserSchema(ma.Schema):
|
|
71
|
+
_links = ma.Hyperlinks(
|
|
72
|
+
{
|
|
73
|
+
"self": ma.URLFor("user_detail", id="<id>"),
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# flask-marshmallow>=0.14.0
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class UserSchema(ma.Schema):
|
|
82
|
+
_links = ma.Hyperlinks(
|
|
83
|
+
{
|
|
84
|
+
"self": ma.URLFor("user_detail", values=dict(id="<id>")),
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
0.13.0 (2020-06-07)
|
|
89
|
+
*******************
|
|
90
|
+
|
|
91
|
+
Bug fixes:
|
|
92
|
+
|
|
93
|
+
* Fix compatibility with marshmallow-sqlalchemy<0.22.0 (:issue:`189`).
|
|
94
|
+
Thanks :user:`PatrickRic` for reporting.
|
|
95
|
+
|
|
96
|
+
Other changes:
|
|
97
|
+
|
|
98
|
+
* Remove unused ``flask_marshmallow.sqla.SchemaOpts``.
|
|
99
|
+
|
|
4
100
|
0.12.0 (2020-04-26)
|
|
5
101
|
*******************
|
|
6
102
|
|
|
@@ -8,8 +104,8 @@ Changelog
|
|
|
8
104
|
|
|
9
105
|
.. warning::
|
|
10
106
|
It is highly recommended that you use the newer ``ma.SQLAlchemySchema`` and ``ma.SQLAlchemyAutoSchema`` classes
|
|
11
|
-
instead of ``ModelSchema`` and ``TableSchema``. See the release notes for `marshmallow-sqlalchemy 0.22.0 <https://marshmallow-sqlalchemy.readthedocs.io/en/latest/changelog.html>`_
|
|
12
|
-
for instructions on how to migrate.
|
|
107
|
+
instead of ``ModelSchema`` and ``TableSchema``. See the release notes for `marshmallow-sqlalchemy 0.22.0 <https://marshmallow-sqlalchemy.readthedocs.io/en/latest/changelog.html>`_
|
|
108
|
+
for instructions on how to migrate.
|
|
13
109
|
|
|
14
110
|
If you need to use ``ModelSchema`` and ``TableSchema`` for the time being, you'll need to import these directly from ``marshmallow_sqlalchemy``.
|
|
15
111
|
|
|
@@ -36,7 +132,7 @@ If you need to use ``ModelSchema`` and ``TableSchema`` for the time being, you'l
|
|
|
36
132
|
# flask-marshmallow>=0.12.0 (recommended)
|
|
37
133
|
|
|
38
134
|
|
|
39
|
-
class AuthorSchema(ma.
|
|
135
|
+
class AuthorSchema(ma.SQLAlchemyAutoSchema):
|
|
40
136
|
class Meta:
|
|
41
137
|
model = Author
|
|
42
138
|
load_instance = True
|
|
@@ -108,14 +108,14 @@ To run syntax checks: ::
|
|
|
108
108
|
|
|
109
109
|
$ tox -e lint
|
|
110
110
|
|
|
111
|
-
(Optional) To run tests
|
|
111
|
+
(Optional) To run tests in all supported Python versions in their own virtual environments (must have each interpreter installed): ::
|
|
112
112
|
|
|
113
113
|
$ tox
|
|
114
114
|
|
|
115
115
|
Documentation
|
|
116
116
|
*************
|
|
117
117
|
|
|
118
|
-
Contributions to the documentation are welcome. Documentation is written in `
|
|
118
|
+
Contributions to the documentation are welcome. Documentation is written in `reStructuredText`_ (rST). A quick rST reference can be found `here <https://docutils.sourceforge.io/docs/user/rst/quickref.html>`_. Builds are powered by Sphinx_.
|
|
119
119
|
|
|
120
120
|
To build the docs in "watch" mode: ::
|
|
121
121
|
|
|
@@ -130,5 +130,5 @@ Have a usage example you'd like to share? Feel free to add it to the `examples <
|
|
|
130
130
|
|
|
131
131
|
|
|
132
132
|
.. _Sphinx: http://sphinx.pocoo.org/
|
|
133
|
-
.. _`
|
|
133
|
+
.. _`reStructuredText`: https://docutils.sourceforge.io/rst.html
|
|
134
134
|
.. _flask-marshmallow: https://github.com/marshmallow-code/flask-marshmallow
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: flask-marshmallow
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Flask + marshmallow for beautiful APIs
|
|
5
|
+
Maintainer-email: Steven Loria <sloria1@gmail.com>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/x-rst
|
|
8
|
+
Classifier: Environment :: Web Environment
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
19
|
+
Requires-Dist: Flask>=2.2
|
|
20
|
+
Requires-Dist: marshmallow>=3.0.0
|
|
21
|
+
Requires-Dist: flask-marshmallow[tests] ; extra == "dev"
|
|
22
|
+
Requires-Dist: tox ; extra == "dev"
|
|
23
|
+
Requires-Dist: pre-commit~=3.5 ; extra == "dev"
|
|
24
|
+
Requires-Dist: marshmallow-sqlalchemy>=0.19.0 ; extra == "docs"
|
|
25
|
+
Requires-Dist: Sphinx==7.2.6 ; extra == "docs"
|
|
26
|
+
Requires-Dist: sphinx-issues==3.0.1 ; extra == "docs"
|
|
27
|
+
Requires-Dist: flask-sqlalchemy>=3.0.0 ; extra == "sqlalchemy"
|
|
28
|
+
Requires-Dist: marshmallow-sqlalchemy>=0.29.0 ; extra == "sqlalchemy"
|
|
29
|
+
Requires-Dist: flask-marshmallow[sqlalchemy] ; extra == "tests"
|
|
30
|
+
Requires-Dist: pytest ; extra == "tests"
|
|
31
|
+
Project-URL: Funding, https://opencollective.com/marshmallow
|
|
32
|
+
Project-URL: Issues, https://github.com/marshmallow-code/flask-marshmallow/issues
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Provides-Extra: docs
|
|
35
|
+
Provides-Extra: sqlalchemy
|
|
36
|
+
Provides-Extra: tests
|
|
37
|
+
|
|
38
|
+
*****************
|
|
39
|
+
Flask-Marshmallow
|
|
40
|
+
*****************
|
|
41
|
+
|
|
42
|
+
|pypi-package| |build-status| |docs| |marshmallow3|
|
|
43
|
+
|
|
44
|
+
Flask + marshmallow for beautiful APIs
|
|
45
|
+
======================================
|
|
46
|
+
|
|
47
|
+
Flask-Marshmallow is a thin integration layer for `Flask`_ (a Python web framework) and `marshmallow`_ (an object serialization/deserialization library) that adds additional features to marshmallow, including URL and Hyperlinks fields for HATEOAS-ready APIs. It also (optionally) integrates with `Flask-SQLAlchemy <http://flask-sqlalchemy.pocoo.org/>`_.
|
|
48
|
+
|
|
49
|
+
Get it now
|
|
50
|
+
----------
|
|
51
|
+
::
|
|
52
|
+
|
|
53
|
+
pip install flask-marshmallow
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
Create your app.
|
|
57
|
+
|
|
58
|
+
.. code-block:: python
|
|
59
|
+
|
|
60
|
+
from flask import Flask
|
|
61
|
+
from flask_marshmallow import Marshmallow
|
|
62
|
+
|
|
63
|
+
app = Flask(__name__)
|
|
64
|
+
ma = Marshmallow(app)
|
|
65
|
+
|
|
66
|
+
Write your models.
|
|
67
|
+
|
|
68
|
+
.. code-block:: python
|
|
69
|
+
|
|
70
|
+
from your_orm import Model, Column, Integer, String, DateTime
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class User(Model):
|
|
74
|
+
email = Column(String)
|
|
75
|
+
password = Column(String)
|
|
76
|
+
date_created = Column(DateTime, auto_now_add=True)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
Define your output format with marshmallow.
|
|
80
|
+
|
|
81
|
+
.. code-block:: python
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class UserSchema(ma.Schema):
|
|
85
|
+
class Meta:
|
|
86
|
+
# Fields to expose
|
|
87
|
+
fields = ("email", "date_created", "_links")
|
|
88
|
+
|
|
89
|
+
# Smart hyperlinking
|
|
90
|
+
_links = ma.Hyperlinks(
|
|
91
|
+
{
|
|
92
|
+
"self": ma.URLFor("user_detail", values=dict(id="<id>")),
|
|
93
|
+
"collection": ma.URLFor("users"),
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
user_schema = UserSchema()
|
|
99
|
+
users_schema = UserSchema(many=True)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
Output the data in your views.
|
|
103
|
+
|
|
104
|
+
.. code-block:: python
|
|
105
|
+
|
|
106
|
+
@app.route("/api/users/")
|
|
107
|
+
def users():
|
|
108
|
+
all_users = User.all()
|
|
109
|
+
return users_schema.dump(all_users)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@app.route("/api/users/<id>")
|
|
113
|
+
def user_detail(id):
|
|
114
|
+
user = User.get(id)
|
|
115
|
+
return user_schema.dump(user)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# {
|
|
119
|
+
# "email": "fred@queen.com",
|
|
120
|
+
# "date_created": "Fri, 25 Apr 2014 06:02:56 -0000",
|
|
121
|
+
# "_links": {
|
|
122
|
+
# "self": "/api/users/42",
|
|
123
|
+
# "collection": "/api/users/"
|
|
124
|
+
# }
|
|
125
|
+
# }
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
http://flask-marshmallow.readthedocs.io/
|
|
129
|
+
========================================
|
|
130
|
+
|
|
131
|
+
Learn More
|
|
132
|
+
==========
|
|
133
|
+
|
|
134
|
+
To learn more about marshmallow, check out its `docs <http://marshmallow.readthedocs.io/en/latest/>`_.
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
Project Links
|
|
139
|
+
=============
|
|
140
|
+
|
|
141
|
+
- Docs: https://flask-marshmallow.readthedocs.io/
|
|
142
|
+
- Changelog: http://flask-marshmallow.readthedocs.io/en/latest/changelog.html
|
|
143
|
+
- PyPI: https://pypi.org/project/flask-marshmallow/
|
|
144
|
+
- Issues: https://github.com/marshmallow-code/flask-marshmallow/issues
|
|
145
|
+
|
|
146
|
+
License
|
|
147
|
+
=======
|
|
148
|
+
|
|
149
|
+
MIT licensed. See the bundled `LICENSE <https://github.com/marshmallow-code/flask-marshmallow/blob/master/LICENSE>`_ file for more details.
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
.. _Flask: http://flask.pocoo.org
|
|
153
|
+
.. _marshmallow: http://marshmallow.readthedocs.io
|
|
154
|
+
|
|
155
|
+
.. |pypi-package| image:: https://badgen.net/pypi/v/flask-marshmallow
|
|
156
|
+
:target: https://pypi.org/project/flask-marshmallow/
|
|
157
|
+
:alt: Latest version
|
|
158
|
+
|
|
159
|
+
.. |build-status| image:: https://github.com/marshmallow-code/flask-marshmallow/actions/workflows/build-release.yml/badge.svg
|
|
160
|
+
:target: https://github.com/marshmallow-code/flask-marshmallow/actions/workflows/build-release.yml
|
|
161
|
+
:alt: Build status
|
|
162
|
+
|
|
163
|
+
.. |docs| image:: https://readthedocs.org/projects/flask-marshmallow/badge/
|
|
164
|
+
:target: https://flask-marshmallow.readthedocs.io/
|
|
165
|
+
:alt: Documentation
|
|
166
|
+
|
|
167
|
+
.. |marshmallow3| image:: https://badgen.net/badge/marshmallow/3
|
|
168
|
+
:target: https://marshmallow.readthedocs.io/en/latest/upgrading.html
|
|
169
|
+
:alt: marshmallow 3 compatible
|
|
170
|
+
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Flask-Marshmallow
|
|
3
3
|
*****************
|
|
4
4
|
|
|
5
|
-
|pypi-package| |build-status| |docs| |
|
|
5
|
+
|pypi-package| |build-status| |docs| |marshmallow3|
|
|
6
6
|
|
|
7
7
|
Flask + marshmallow for beautiful APIs
|
|
8
8
|
======================================
|
|
@@ -51,7 +51,10 @@ Define your output format with marshmallow.
|
|
|
51
51
|
|
|
52
52
|
# Smart hyperlinking
|
|
53
53
|
_links = ma.Hyperlinks(
|
|
54
|
-
{
|
|
54
|
+
{
|
|
55
|
+
"self": ma.URLFor("user_detail", values=dict(id="<id>")),
|
|
56
|
+
"collection": ma.URLFor("users"),
|
|
57
|
+
}
|
|
55
58
|
)
|
|
56
59
|
|
|
57
60
|
|
|
@@ -100,7 +103,7 @@ Project Links
|
|
|
100
103
|
|
|
101
104
|
- Docs: https://flask-marshmallow.readthedocs.io/
|
|
102
105
|
- Changelog: http://flask-marshmallow.readthedocs.io/en/latest/changelog.html
|
|
103
|
-
- PyPI: https://pypi.
|
|
106
|
+
- PyPI: https://pypi.org/project/flask-marshmallow/
|
|
104
107
|
- Issues: https://github.com/marshmallow-code/flask-marshmallow/issues
|
|
105
108
|
|
|
106
109
|
License
|
|
@@ -115,15 +118,15 @@ MIT licensed. See the bundled `LICENSE <https://github.com/marshmallow-code/flas
|
|
|
115
118
|
.. |pypi-package| image:: https://badgen.net/pypi/v/flask-marshmallow
|
|
116
119
|
:target: https://pypi.org/project/flask-marshmallow/
|
|
117
120
|
:alt: Latest version
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
|
|
122
|
+
.. |build-status| image:: https://github.com/marshmallow-code/flask-marshmallow/actions/workflows/build-release.yml/badge.svg
|
|
123
|
+
:target: https://github.com/marshmallow-code/flask-marshmallow/actions/workflows/build-release.yml
|
|
120
124
|
:alt: Build status
|
|
125
|
+
|
|
121
126
|
.. |docs| image:: https://readthedocs.org/projects/flask-marshmallow/badge/
|
|
122
127
|
:target: https://flask-marshmallow.readthedocs.io/
|
|
123
128
|
:alt: Documentation
|
|
124
|
-
|
|
129
|
+
|
|
130
|
+
.. |marshmallow3| image:: https://badgen.net/badge/marshmallow/3
|
|
125
131
|
:target: https://marshmallow.readthedocs.io/en/latest/upgrading.html
|
|
126
132
|
:alt: marshmallow 3 compatible
|
|
127
|
-
.. |black| image:: https://badgen.net/badge/code%20style/black/000
|
|
128
|
-
:target: https://github.com/ambv/black
|
|
129
|
-
:alt: code style: black
|
|
@@ -14,7 +14,7 @@ Flask + marshmallow for beautiful APIs
|
|
|
14
14
|
|
|
15
15
|
<h3>Useful Links</h3>
|
|
16
16
|
<ul>
|
|
17
|
-
<li><a href="
|
|
17
|
+
<li><a href="https://pypi.org/project/flask-marshmallow/">Flask-Marshmallow @ PyPI</a></li>
|
|
18
18
|
<li><a href="http://github.com/marshmallow-code/flask-marshmallow">Flask-Marshmallow @ GitHub</a></li>
|
|
19
19
|
<li><a href="http://github.com/marshmallow-code/flask-marshmallow/issues">Issue Tracker</a></li>
|
|
20
20
|
</ul>
|
|
@@ -18,7 +18,7 @@ Flask + marshmallow for beautiful APIs
|
|
|
18
18
|
|
|
19
19
|
<h3>Useful Links</h3>
|
|
20
20
|
<ul>
|
|
21
|
-
<li><a href="
|
|
21
|
+
<li><a href="https://pypi.org/project/flask-marshmallow/">Flask-Marshmallow @ PyPI</a></li>
|
|
22
22
|
<li><a href="http://github.com/marshmallow-code/flask-marshmallow">Flask-Marshmallow @ GitHub</a></li>
|
|
23
23
|
<li><a href="http://github.com/marshmallow-code/flask-marshmallow/issues">Issue Tracker</a></li>
|
|
24
24
|
</ul>
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
1
|
import datetime as dt
|
|
3
|
-
import
|
|
2
|
+
import importlib.metadata
|
|
4
3
|
import os
|
|
5
|
-
|
|
6
|
-
sys.path.insert(0, os.path.abspath(os.path.join("..", "src")))
|
|
7
|
-
import flask_marshmallow # noqa: E402
|
|
4
|
+
import sys
|
|
8
5
|
|
|
9
6
|
sys.path.append(os.path.abspath("_themes"))
|
|
10
7
|
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx_issues"]
|
|
@@ -34,13 +31,13 @@ source_suffix = ".rst"
|
|
|
34
31
|
master_doc = "index"
|
|
35
32
|
|
|
36
33
|
# General information about the project.
|
|
37
|
-
project =
|
|
38
|
-
copyright =
|
|
34
|
+
project = "Flask-Marshmallow"
|
|
35
|
+
copyright = "2014-{:%Y}".format(
|
|
39
36
|
dt.datetime.utcfromtimestamp(os.path.getmtime("../CHANGELOG.rst"))
|
|
40
37
|
)
|
|
41
38
|
|
|
42
39
|
|
|
43
|
-
version = release =
|
|
40
|
+
version = release = importlib.metadata.version("flask-marshmallow")
|
|
44
41
|
exclude_patterns = ["_build"]
|
|
45
42
|
# The name of the Pygments (syntax highlighting) style to use.
|
|
46
43
|
pygments_style = "flask_theme_support.FlaskyStyle"
|
|
@@ -4,7 +4,7 @@ Flask-Marshmallow: Flask + marshmallow for beautiful APIs
|
|
|
4
4
|
|
|
5
5
|
:ref:`changelog <changelog>` //
|
|
6
6
|
`github <http://github.com/marshmallow-code/flask-marshmallow>`_ //
|
|
7
|
-
`pypi <
|
|
7
|
+
`pypi <https://pypi.org/project/flask-marshmallow/>`_ //
|
|
8
8
|
`issues <http://github.com/marshmallow-code/flask-marshmallow/issues>`_
|
|
9
9
|
|
|
10
10
|
|
|
@@ -55,7 +55,10 @@ Define your output format with marshmallow.
|
|
|
55
55
|
|
|
56
56
|
# Smart hyperlinking
|
|
57
57
|
_links = ma.Hyperlinks(
|
|
58
|
-
{
|
|
58
|
+
{
|
|
59
|
+
"self": ma.URLFor("user_detail", values=dict(id="<id>")),
|
|
60
|
+
"collection": ma.URLFor("users"),
|
|
61
|
+
}
|
|
59
62
|
)
|
|
60
63
|
|
|
61
64
|
|
|
@@ -175,6 +178,7 @@ You can now use your schema to dump and load your ORM objects.
|
|
|
175
178
|
|
|
176
179
|
- By default, `~flask_marshmallow.sqla.SQLAlchemySchema` uses the scoped session created by Flask-SQLAlchemy.
|
|
177
180
|
- `~flask_marshmallow.sqla.SQLAlchemySchema` subclasses `flask_marshmallow.Schema`, so it includes the `~flask_marshmallow.Schema.jsonify` method.
|
|
181
|
+
|
|
178
182
|
Note: By default, Flask's `jsonify` method sorts the list of keys and returns consistent results to ensure that external HTTP caches aren't trashed. As a side effect, this will override `ordered=True <https://marshmallow.readthedocs.io/en/latest/quickstart.html#ordering-output>`_
|
|
179
183
|
in the SQLAlchemySchema's `class Meta` (if you set it). To disable this, set `JSON_SORT_KEYS=False` in your Flask app config. In production it's recommended to let `jsonify` sort the keys and not set `ordered=True` in your `~flask_marshmallow.sqla.SQLAlchemySchema` in order to minimize generation time and maximize cacheability of the results.
|
|
180
184
|
|
|
@@ -225,6 +229,9 @@ API
|
|
|
225
229
|
.. automodule:: flask_marshmallow.fields
|
|
226
230
|
:members:
|
|
227
231
|
|
|
232
|
+
.. automodule:: flask_marshmallow.validate
|
|
233
|
+
:members:
|
|
234
|
+
|
|
228
235
|
.. automodule:: flask_marshmallow.sqla
|
|
229
236
|
:members:
|
|
230
237
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "flask-marshmallow"
|
|
3
|
+
version = "1.1.0"
|
|
4
|
+
description = "Flask + marshmallow for beautiful APIs"
|
|
5
|
+
readme = "README.rst"
|
|
6
|
+
license = { file = "LICENSE" }
|
|
7
|
+
maintainers = [{ name = "Steven Loria", email = "sloria1@gmail.com" }]
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Environment :: Web Environment",
|
|
10
|
+
"Intended Audience :: Developers",
|
|
11
|
+
"License :: OSI Approved :: MIT License",
|
|
12
|
+
"Natural Language :: English",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.8",
|
|
15
|
+
"Programming Language :: Python :: 3.9",
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
|
|
20
|
+
]
|
|
21
|
+
requires-python = ">=3.8"
|
|
22
|
+
dependencies = ["Flask>=2.2", "marshmallow>=3.0.0"]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Issues = "https://github.com/marshmallow-code/flask-marshmallow/issues"
|
|
26
|
+
Funding = "https://opencollective.com/marshmallow"
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
docs = [
|
|
30
|
+
"marshmallow-sqlalchemy>=0.19.0",
|
|
31
|
+
"Sphinx==7.2.6",
|
|
32
|
+
"sphinx-issues==3.0.1",
|
|
33
|
+
]
|
|
34
|
+
tests = ["flask-marshmallow[sqlalchemy]", "pytest"]
|
|
35
|
+
dev = ["flask-marshmallow[tests]", "tox", "pre-commit~=3.5"]
|
|
36
|
+
sqlalchemy = ["flask-sqlalchemy>=3.0.0", "marshmallow-sqlalchemy>=0.29.0"]
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["flit_core<4"]
|
|
40
|
+
build-backend = "flit_core.buildapi"
|
|
41
|
+
|
|
42
|
+
[tool.flit.sdist]
|
|
43
|
+
include = ["docs/", "tests/", "CHANGELOG.rst", "CONTRIBUTING.rst", "tox.ini"]
|
|
44
|
+
exclude = ["docs/_build/"]
|
|
45
|
+
|
|
46
|
+
[tool.ruff]
|
|
47
|
+
src = ["src"]
|
|
48
|
+
fix = true
|
|
49
|
+
show-fixes = true
|
|
50
|
+
show-source = true
|
|
51
|
+
|
|
52
|
+
[tool.ruff.lint]
|
|
53
|
+
select = [
|
|
54
|
+
"B", # flake8-bugbear
|
|
55
|
+
"E", # pycodestyle error
|
|
56
|
+
"F", # pyflakes
|
|
57
|
+
"I", # isort
|
|
58
|
+
"UP", # pyupgrade
|
|
59
|
+
"W", # pycodestyle warning
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
[tool.pytest.ini_options]
|
|
63
|
+
filterwarnings = [
|
|
64
|
+
"error",
|
|
65
|
+
"ignore:distutils Version classes are deprecated\\. Use packaging.version instead\\.:DeprecationWarning:marshmallow",
|
|
66
|
+
]
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
1
|
"""
|
|
3
2
|
flask_marshmallow
|
|
4
3
|
~~~~~~~~~~~~~~~~~
|
|
@@ -6,14 +5,18 @@
|
|
|
6
5
|
Integrates the marshmallow serialization/deserialization library
|
|
7
6
|
with your Flask application.
|
|
8
7
|
"""
|
|
8
|
+
import typing
|
|
9
9
|
import warnings
|
|
10
|
-
from distutils.version import LooseVersion
|
|
11
10
|
|
|
12
|
-
from marshmallow import
|
|
11
|
+
from marshmallow import exceptions, pprint
|
|
12
|
+
from marshmallow import fields as base_fields
|
|
13
13
|
|
|
14
14
|
from . import fields
|
|
15
15
|
from .schema import Schema
|
|
16
16
|
|
|
17
|
+
if typing.TYPE_CHECKING:
|
|
18
|
+
from flask import Flask
|
|
19
|
+
|
|
17
20
|
has_sqla = False
|
|
18
21
|
try:
|
|
19
22
|
import flask_sqlalchemy # noqa: F401
|
|
@@ -25,14 +28,20 @@ else:
|
|
|
25
28
|
except ImportError:
|
|
26
29
|
warnings.warn(
|
|
27
30
|
"Flask-SQLAlchemy integration requires "
|
|
28
|
-
"marshmallow-sqlalchemy to be installed."
|
|
31
|
+
"marshmallow-sqlalchemy to be installed.",
|
|
32
|
+
stacklevel=2,
|
|
29
33
|
)
|
|
30
34
|
else:
|
|
31
35
|
has_sqla = True
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
__all__ = [
|
|
38
|
+
"EXTENSION_NAME",
|
|
39
|
+
"Marshmallow",
|
|
40
|
+
"Schema",
|
|
41
|
+
"fields",
|
|
42
|
+
"exceptions",
|
|
43
|
+
"pprint",
|
|
44
|
+
]
|
|
36
45
|
|
|
37
46
|
EXTENSION_NAME = "flask-marshmallow"
|
|
38
47
|
|
|
@@ -48,7 +57,7 @@ def _attach_fields(obj):
|
|
|
48
57
|
setattr(obj, attr, getattr(fields, attr))
|
|
49
58
|
|
|
50
59
|
|
|
51
|
-
class Marshmallow
|
|
60
|
+
class Marshmallow:
|
|
52
61
|
"""Wrapper class that integrates Marshmallow with a Flask application.
|
|
53
62
|
|
|
54
63
|
To use it, instantiate with an application::
|
|
@@ -71,19 +80,20 @@ class Marshmallow(object):
|
|
|
71
80
|
author = ma.Nested(AuthorSchema)
|
|
72
81
|
|
|
73
82
|
links = ma.Hyperlinks({
|
|
74
|
-
'self': ma.URLFor('book_detail', id='<id>'),
|
|
83
|
+
'self': ma.URLFor('book_detail', values=dict(id='<id>')),
|
|
75
84
|
'collection': ma.URLFor('book_list')
|
|
76
85
|
})
|
|
77
86
|
|
|
78
87
|
|
|
79
|
-
In order to integrate with Flask-SQLAlchemy, this extension must be initialized
|
|
80
|
-
`flask_sqlalchemy.SQLAlchemy`. ::
|
|
88
|
+
In order to integrate with Flask-SQLAlchemy, this extension must be initialized
|
|
89
|
+
*after* `flask_sqlalchemy.SQLAlchemy`. ::
|
|
81
90
|
|
|
82
91
|
db = SQLAlchemy(app)
|
|
83
92
|
ma = Marshmallow(app)
|
|
84
93
|
|
|
85
|
-
This gives you access to `ma.SQLAlchemySchema` and `ma.SQLAlchemyAutoSchema`, which
|
|
86
|
-
marshmallow `~marshmallow.Schema` classes
|
|
94
|
+
This gives you access to `ma.SQLAlchemySchema` and `ma.SQLAlchemyAutoSchema`, which
|
|
95
|
+
generate marshmallow `~marshmallow.Schema` classes
|
|
96
|
+
based on the passed in model or table. ::
|
|
87
97
|
|
|
88
98
|
class AuthorSchema(ma.SQLAlchemyAutoSchema):
|
|
89
99
|
class Meta:
|
|
@@ -92,7 +102,7 @@ class Marshmallow(object):
|
|
|
92
102
|
:param Flask app: The Flask application object.
|
|
93
103
|
"""
|
|
94
104
|
|
|
95
|
-
def __init__(self, app=None):
|
|
105
|
+
def __init__(self, app: typing.Optional["Flask"] = None):
|
|
96
106
|
self.Schema = Schema
|
|
97
107
|
if has_sqla:
|
|
98
108
|
self.SQLAlchemySchema = sqla.SQLAlchemySchema
|
|
@@ -103,16 +113,16 @@ class Marshmallow(object):
|
|
|
103
113
|
if app is not None:
|
|
104
114
|
self.init_app(app)
|
|
105
115
|
|
|
106
|
-
def init_app(self, app):
|
|
116
|
+
def init_app(self, app: "Flask"):
|
|
107
117
|
"""Initializes the application with the extension.
|
|
108
118
|
|
|
109
119
|
:param Flask app: The Flask application object.
|
|
110
120
|
"""
|
|
111
121
|
app.extensions = getattr(app, "extensions", {})
|
|
112
122
|
|
|
113
|
-
# If using Flask-SQLAlchemy, attach db.session to
|
|
123
|
+
# If using Flask-SQLAlchemy, attach db.session to SQLAlchemySchema
|
|
114
124
|
if has_sqla and "sqlalchemy" in app.extensions:
|
|
115
|
-
db = app.extensions["sqlalchemy"]
|
|
125
|
+
db = app.extensions["sqlalchemy"]
|
|
116
126
|
self.SQLAlchemySchema.OPTIONS_CLASS.session = db.session
|
|
117
127
|
self.SQLAlchemyAutoSchema.OPTIONS_CLASS.session = db.session
|
|
118
128
|
app.extensions[EXTENSION_NAME] = self
|