flask-marshmallow


Nameflask-marshmallow JSON
Version 1.2.1 PyPI version JSON
download
home_page
SummaryFlask + marshmallow for beautiful APIs
upload_time2024-03-18 19:09:47
maintainer
docs_urlNone
author
requires_python>=3.8
license
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| |marshmallow3|

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):
        class Meta:
            # Fields to expose
            fields = ("email", "date_created", "_links")

        # 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

.. |marshmallow3| image:: https://badgen.net/badge/marshmallow/3
    :target: https://marshmallow.readthedocs.io/en/latest/upgrading.html
    :alt: marshmallow 3 compatible


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "flask-marshmallow",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Steven Loria <sloria1@gmail.com>, Stephen Rosen <sirosen0@gmail.com>",
    "keywords": "",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/bf/9c/0c0cee00441981502358b4bc6e3d1b21247d3d80a277dde18bf3d0ad7426/flask_marshmallow-1.2.1.tar.gz",
    "platform": null,
    "description": "*****************\nFlask-Marshmallow\n*****************\n\n|pypi-package| |build-status| |docs| |marshmallow3|\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        class Meta:\n            # Fields to expose\n            fields = (\"email\", \"date_created\", \"_links\")\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.. |marshmallow3| image:: https://badgen.net/badge/marshmallow/3\n    :target: https://marshmallow.readthedocs.io/en/latest/upgrading.html\n    :alt: marshmallow 3 compatible\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Flask + marshmallow for beautiful APIs",
    "version": "1.2.1",
    "project_urls": {
        "Funding": "https://opencollective.com/marshmallow",
        "Issues": "https://github.com/marshmallow-code/flask-marshmallow/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6858b20b1c8e3174479ea23388d61a9772132586ff492a280acbc84082a2a176",
                "md5": "ddc3c5699abc420a5fd306be8dd5ccca",
                "sha256": "10b5048ecfaa26f7c8d0aed7d81083164450e6be8e81c04b3d4a586b3f7b6678"
            },
            "downloads": -1,
            "filename": "flask_marshmallow-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ddc3c5699abc420a5fd306be8dd5ccca",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12093,
            "upload_time": "2024-03-18T19:09:44",
            "upload_time_iso_8601": "2024-03-18T19:09:44.347344Z",
            "url": "https://files.pythonhosted.org/packages/68/58/b20b1c8e3174479ea23388d61a9772132586ff492a280acbc84082a2a176/flask_marshmallow-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bf9c0c0cee00441981502358b4bc6e3d1b21247d3d80a277dde18bf3d0ad7426",
                "md5": "390010c2e3b7a05a72b7c9dcd8a39315",
                "sha256": "00ee96399ed664963afff3b5d6ee518640b0f91dbc2aace2b5abcf32f40ef23a"
            },
            "downloads": -1,
            "filename": "flask_marshmallow-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "390010c2e3b7a05a72b7c9dcd8a39315",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 40752,
            "upload_time": "2024-03-18T19:09:47",
            "upload_time_iso_8601": "2024-03-18T19:09:47.612000Z",
            "url": "https://files.pythonhosted.org/packages/bf/9c/0c0cee00441981502358b4bc6e3d1b21247d3d80a277dde18bf3d0ad7426/flask_marshmallow-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-18 19:09:47",
    "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.24101s