flask-marshmallow


Nameflask-marshmallow JSON
Version 1.3.0 PyPI version JSON
download
home_pageNone
SummaryFlask + marshmallow for beautiful APIs
upload_time2025-01-07 04:04:07
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            *****************
Flask-Marshmallow
*****************

|pypi-package| |build-status| |docs| |marshmallow-support|

Flask + marshmallow for beautiful APIs
======================================

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/>`_.

Get it now
----------
::

    pip install flask-marshmallow


Create your app.

.. code-block:: python

    from flask import Flask
    from flask_marshmallow import Marshmallow

    app = Flask(__name__)
    ma = Marshmallow(app)

Write your models.

.. code-block:: python

    from your_orm import Model, Column, Integer, String, DateTime


    class User(Model):
        email = Column(String)
        password = Column(String)
        date_created = Column(DateTime, auto_now_add=True)


Define your output format with marshmallow.

.. code-block:: python


    class UserSchema(ma.Schema):
        email = ma.Email()
        date_created = ma.DateTime()

        # Smart hyperlinking
        _links = ma.Hyperlinks(
            {
                "self": ma.URLFor("user_detail", values=dict(id="<id>")),
                "collection": ma.URLFor("users"),
            }
        )


    user_schema = UserSchema()
    users_schema = UserSchema(many=True)


Output the data in your views.

.. code-block:: python

    @app.route("/api/users/")
    def users():
        all_users = User.all()
        return users_schema.dump(all_users)


    @app.route("/api/users/<id>")
    def user_detail(id):
        user = User.get(id)
        return user_schema.dump(user)


    # {
    #     "email": "fred@queen.com",
    #     "date_created": "Fri, 25 Apr 2014 06:02:56 -0000",
    #     "_links": {
    #         "self": "/api/users/42",
    #         "collection": "/api/users/"
    #     }
    # }


http://flask-marshmallow.readthedocs.io/
========================================

Learn More
==========

To learn more about marshmallow, check out its `docs <http://marshmallow.readthedocs.io/en/latest/>`_.



Project Links
=============

- Docs: https://flask-marshmallow.readthedocs.io/
- Changelog: http://flask-marshmallow.readthedocs.io/en/latest/changelog.html
- PyPI: https://pypi.org/project/flask-marshmallow/
- Issues: https://github.com/marshmallow-code/flask-marshmallow/issues

License
=======

MIT licensed. See the bundled `LICENSE <https://github.com/marshmallow-code/flask-marshmallow/blob/master/LICENSE>`_ file for more details.


.. _Flask: http://flask.pocoo.org
.. _marshmallow: http://marshmallow.readthedocs.io

.. |pypi-package| image:: https://badgen.net/pypi/v/flask-marshmallow
    :target: https://pypi.org/project/flask-marshmallow/
    :alt: Latest version

.. |build-status| image:: https://github.com/marshmallow-code/flask-marshmallow/actions/workflows/build-release.yml/badge.svg
    :target: https://github.com/marshmallow-code/flask-marshmallow/actions/workflows/build-release.yml
    :alt: Build status

.. |docs| image:: https://readthedocs.org/projects/flask-marshmallow/badge/
   :target: https://flask-marshmallow.readthedocs.io/
   :alt: Documentation

.. |marshmallow-support| image:: https://badgen.net/badge/marshmallow/3,4?list=1
    :target: https://marshmallow.readthedocs.io/en/latest/upgrading.html
    :alt: marshmallow 3|4 compatible


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "flask-marshmallow",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Steven Loria <sloria1@gmail.com>, Stephen Rosen <sirosen0@gmail.com>",
    "keywords": null,
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/66/91/f3893613c3a388a643f8a96e1b08a17b863fcc03beb6f2a40bb224da7df7/flask_marshmallow-1.3.0.tar.gz",
    "platform": null,
    "description": "*****************\nFlask-Marshmallow\n*****************\n\n|pypi-package| |build-status| |docs| |marshmallow-support|\n\nFlask + marshmallow for beautiful APIs\n======================================\n\nFlask-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/>`_.\n\nGet it now\n----------\n::\n\n    pip install flask-marshmallow\n\n\nCreate your app.\n\n.. code-block:: python\n\n    from flask import Flask\n    from flask_marshmallow import Marshmallow\n\n    app = Flask(__name__)\n    ma = Marshmallow(app)\n\nWrite your models.\n\n.. code-block:: python\n\n    from your_orm import Model, Column, Integer, String, DateTime\n\n\n    class User(Model):\n        email = Column(String)\n        password = Column(String)\n        date_created = Column(DateTime, auto_now_add=True)\n\n\nDefine your output format with marshmallow.\n\n.. code-block:: python\n\n\n    class UserSchema(ma.Schema):\n        email = ma.Email()\n        date_created = ma.DateTime()\n\n        # Smart hyperlinking\n        _links = ma.Hyperlinks(\n            {\n                \"self\": ma.URLFor(\"user_detail\", values=dict(id=\"<id>\")),\n                \"collection\": ma.URLFor(\"users\"),\n            }\n        )\n\n\n    user_schema = UserSchema()\n    users_schema = UserSchema(many=True)\n\n\nOutput the data in your views.\n\n.. code-block:: python\n\n    @app.route(\"/api/users/\")\n    def users():\n        all_users = User.all()\n        return users_schema.dump(all_users)\n\n\n    @app.route(\"/api/users/<id>\")\n    def user_detail(id):\n        user = User.get(id)\n        return user_schema.dump(user)\n\n\n    # {\n    #     \"email\": \"fred@queen.com\",\n    #     \"date_created\": \"Fri, 25 Apr 2014 06:02:56 -0000\",\n    #     \"_links\": {\n    #         \"self\": \"/api/users/42\",\n    #         \"collection\": \"/api/users/\"\n    #     }\n    # }\n\n\nhttp://flask-marshmallow.readthedocs.io/\n========================================\n\nLearn More\n==========\n\nTo learn more about marshmallow, check out its `docs <http://marshmallow.readthedocs.io/en/latest/>`_.\n\n\n\nProject Links\n=============\n\n- Docs: https://flask-marshmallow.readthedocs.io/\n- Changelog: http://flask-marshmallow.readthedocs.io/en/latest/changelog.html\n- PyPI: https://pypi.org/project/flask-marshmallow/\n- Issues: https://github.com/marshmallow-code/flask-marshmallow/issues\n\nLicense\n=======\n\nMIT licensed. See the bundled `LICENSE <https://github.com/marshmallow-code/flask-marshmallow/blob/master/LICENSE>`_ file for more details.\n\n\n.. _Flask: http://flask.pocoo.org\n.. _marshmallow: http://marshmallow.readthedocs.io\n\n.. |pypi-package| image:: https://badgen.net/pypi/v/flask-marshmallow\n    :target: https://pypi.org/project/flask-marshmallow/\n    :alt: Latest version\n\n.. |build-status| image:: https://github.com/marshmallow-code/flask-marshmallow/actions/workflows/build-release.yml/badge.svg\n    :target: https://github.com/marshmallow-code/flask-marshmallow/actions/workflows/build-release.yml\n    :alt: Build status\n\n.. |docs| image:: https://readthedocs.org/projects/flask-marshmallow/badge/\n   :target: https://flask-marshmallow.readthedocs.io/\n   :alt: Documentation\n\n.. |marshmallow-support| image:: https://badgen.net/badge/marshmallow/3,4?list=1\n    :target: https://marshmallow.readthedocs.io/en/latest/upgrading.html\n    :alt: marshmallow 3|4 compatible\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Flask + marshmallow for beautiful APIs",
    "version": "1.3.0",
    "project_urls": {
        "Funding": "https://opencollective.com/marshmallow",
        "Issues": "https://github.com/marshmallow-code/flask-marshmallow/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27cd5b3d4103460766eb834f6deaf26a87a4735a0c9687f24163e07d1f3d7791",
                "md5": "bc14f51751d3326d28e0e8cb12bbcf8d",
                "sha256": "c0a0644b46406851873ab41c1e8a7de3ef27fa69b00b89bf630f1696ec0813a0"
            },
            "downloads": -1,
            "filename": "flask_marshmallow-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bc14f51751d3326d28e0e8cb12bbcf8d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 12174,
            "upload_time": "2025-01-07T04:04:06",
            "upload_time_iso_8601": "2025-01-07T04:04:06.326126Z",
            "url": "https://files.pythonhosted.org/packages/27/cd/5b3d4103460766eb834f6deaf26a87a4735a0c9687f24163e07d1f3d7791/flask_marshmallow-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6691f3893613c3a388a643f8a96e1b08a17b863fcc03beb6f2a40bb224da7df7",
                "md5": "7496bced9c3196a9382695504326daf1",
                "sha256": "27a35d0ce5dcba161cc5f2f4764afbc2536c93fa439a793250b827835e3f3be6"
            },
            "downloads": -1,
            "filename": "flask_marshmallow-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7496bced9c3196a9382695504326daf1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 40852,
            "upload_time": "2025-01-07T04:04:07",
            "upload_time_iso_8601": "2025-01-07T04:04:07.757208Z",
            "url": "https://files.pythonhosted.org/packages/66/91/f3893613c3a388a643f8a96e1b08a17b863fcc03beb6f2a40bb224da7df7/flask_marshmallow-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-07 04:04:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "marshmallow-code",
    "github_project": "flask-marshmallow",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "flask-marshmallow"
}
        
Elapsed time: 0.64901s