marshmallow-sqlalchemy-pk


Namemarshmallow-sqlalchemy-pk JSON
Version 0.13.2 PyPI version JSON
download
home_pagehttps://github.com/tispratik/marshmallow-sqlalchemy
SummarySQLAlchemy integration with the marshmallow (de)serialization library
upload_time2018-03-08 01:09:09
maintainer
docs_urlNone
authorSteven Loria
requires_python
licenseMIT
keywords sqlalchemy marshmallow
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            **********************
marshmallow-sqlalchemy
**********************

|pypi-package| |build-status| |docs|

Homepage: https://marshmallow-sqlalchemy.readthedocs.io/

`SQLAlchemy <http://www.sqlalchemy.org/>`_ integration with the  `marshmallow <https://marshmallow.readthedocs.io/en/latest/>`_ (de)serialization library.

Declare your models
===================

.. code-block:: python

    import sqlalchemy as sa
    from sqlalchemy.ext.declarative import declarative_base
    from sqlalchemy.orm import scoped_session, sessionmaker, relationship, backref

    engine = sa.create_engine('sqlite:///:memory:')
    session = scoped_session(sessionmaker(bind=engine))
    Base = declarative_base()

    class Author(Base):
        __tablename__ = 'authors'
        id = sa.Column(sa.Integer, primary_key=True)
        name = sa.Column(sa.String)

        def __repr__(self):
            return '<Author(name={self.name!r})>'.format(self=self)

    class Book(Base):
        __tablename__ = 'books'
        id = sa.Column(sa.Integer, primary_key=True)
        title = sa.Column(sa.String)
        author_id = sa.Column(sa.Integer, sa.ForeignKey('authors.id'))
        author = relationship("Author", backref=backref('books'))

    Base.metadata.create_all(engine)

Generate marshmallow schemas
============================

.. code-block:: python

    from marshmallow_sqlalchemy import ModelSchema

    class AuthorSchema(ModelSchema):
        class Meta:
            model = Author

    class BookSchema(ModelSchema):
        class Meta:
            model = Book
            # optionally attach a Session
            # to use for deserialization
            sqla_session = session

    author_schema = AuthorSchema()

(De)serialize your data
=======================

.. code-block:: python

    author = Author(name='Chuck Paluhniuk')
    book = Book(title='Fight Club', author=author)
    session.add(author)
    session.add(book)
    session.commit()

    author_schema.dump(author).data
    # {'books': [123], 'id': 321, 'name': 'Chuck Paluhniuk'}

    author_schema.load(dump_data, session=session).data
    # <Author(name='Chuck Paluhniuk')>

Get it now
==========
::

   pip install -U marshmallow-sqlalchemy


Documentation
=============

Documentation is available at https://marshmallow-sqlalchemy.readthedocs.io/ .

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

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

License
=======

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


.. |pypi-package| image:: https://badge.fury.io/py/marshmallow-sqlalchemy.svg
    :target: http://badge.fury.io/py/marshmallow-sqlalchemy
    :alt: Latest version
.. |build-status| image:: https://travis-ci.org/marshmallow-code/marshmallow-sqlalchemy.svg?branch=dev
    :target: https://travis-ci.org/marshmallow-code/marshmallow-sqlalchemy
    :alt: Travis-CI
.. |docs| image:: https://readthedocs.org/projects/marshmallow-sqlalchemy/badge/
   :target: http://marshmallow-sqlalchemy.readthedocs.io/
   :alt: Documentation

            

Raw data

            {
    "maintainer": "", 
    "docs_url": null, 
    "requires_python": "", 
    "maintainer_email": "", 
    "cheesecake_code_kwalitee_id": null, 
    "keywords": "sqlalchemy marshmallow", 
    "upload_time": "2018-03-08 01:09:09", 
    "author": "Steven Loria", 
    "home_page": "https://github.com/tispratik/marshmallow-sqlalchemy", 
    "github_user": "tispratik", 
    "download_url": "https://pypi.python.org/packages/a0/fe/b0bec7c3b40fb3f4956af457eefcfb9dbc74bb0632040f523a1608404da6/marshmallow-sqlalchemy-pk-0.13.2.tar.gz", 
    "platform": "", 
    "version": "0.13.2", 
    "cheesecake_documentation_id": null, 
    "description": "**********************\nmarshmallow-sqlalchemy\n**********************\n\n|pypi-package| |build-status| |docs|\n\nHomepage: https://marshmallow-sqlalchemy.readthedocs.io/\n\n`SQLAlchemy <http://www.sqlalchemy.org/>`_ integration with the  `marshmallow <https://marshmallow.readthedocs.io/en/latest/>`_ (de)serialization library.\n\nDeclare your models\n===================\n\n.. code-block:: python\n\n    import sqlalchemy as sa\n    from sqlalchemy.ext.declarative import declarative_base\n    from sqlalchemy.orm import scoped_session, sessionmaker, relationship, backref\n\n    engine = sa.create_engine('sqlite:///:memory:')\n    session = scoped_session(sessionmaker(bind=engine))\n    Base = declarative_base()\n\n    class Author(Base):\n        __tablename__ = 'authors'\n        id = sa.Column(sa.Integer, primary_key=True)\n        name = sa.Column(sa.String)\n\n        def __repr__(self):\n            return '<Author(name={self.name!r})>'.format(self=self)\n\n    class Book(Base):\n        __tablename__ = 'books'\n        id = sa.Column(sa.Integer, primary_key=True)\n        title = sa.Column(sa.String)\n        author_id = sa.Column(sa.Integer, sa.ForeignKey('authors.id'))\n        author = relationship(\"Author\", backref=backref('books'))\n\n    Base.metadata.create_all(engine)\n\nGenerate marshmallow schemas\n============================\n\n.. code-block:: python\n\n    from marshmallow_sqlalchemy import ModelSchema\n\n    class AuthorSchema(ModelSchema):\n        class Meta:\n            model = Author\n\n    class BookSchema(ModelSchema):\n        class Meta:\n            model = Book\n            # optionally attach a Session\n            # to use for deserialization\n            sqla_session = session\n\n    author_schema = AuthorSchema()\n\n(De)serialize your data\n=======================\n\n.. code-block:: python\n\n    author = Author(name='Chuck Paluhniuk')\n    book = Book(title='Fight Club', author=author)\n    session.add(author)\n    session.add(book)\n    session.commit()\n\n    author_schema.dump(author).data\n    # {'books': [123], 'id': 321, 'name': 'Chuck Paluhniuk'}\n\n    author_schema.load(dump_data, session=session).data\n    # <Author(name='Chuck Paluhniuk')>\n\nGet it now\n==========\n::\n\n   pip install -U marshmallow-sqlalchemy\n\n\nDocumentation\n=============\n\nDocumentation is available at https://marshmallow-sqlalchemy.readthedocs.io/ .\n\nProject Links\n=============\n\n- Docs: https://marshmallow-sqlalchemy.readthedocs.io/\n- Changelog: https://marshmallow-sqlalchemy.readthedocs.io/en/latest/changelog.html\n- PyPI: https://pypi.python.org/pypi/marshmallow-sqlalchemy\n- Issues: https://github.com/marshmallow-code/marshmallow-sqlalchemy/issues\n\nLicense\n=======\n\nMIT licensed. See the bundled `LICENSE <https://github.com/marshmallow-code/marshmallow-sqlalchemy/blob/dev/LICENSE>`_ file for more details.\n\n\n.. |pypi-package| image:: https://badge.fury.io/py/marshmallow-sqlalchemy.svg\n    :target: http://badge.fury.io/py/marshmallow-sqlalchemy\n    :alt: Latest version\n.. |build-status| image:: https://travis-ci.org/marshmallow-code/marshmallow-sqlalchemy.svg?branch=dev\n    :target: https://travis-ci.org/marshmallow-code/marshmallow-sqlalchemy\n    :alt: Travis-CI\n.. |docs| image:: https://readthedocs.org/projects/marshmallow-sqlalchemy/badge/\n   :target: http://marshmallow-sqlalchemy.readthedocs.io/\n   :alt: Documentation\n", 
    "tox": true, 
    "lcname": "marshmallow-sqlalchemy-pk", 
    "bugtrack_url": null, 
    "github": true, 
    "coveralls": false, 
    "name": "marshmallow-sqlalchemy-pk", 
    "license": "MIT", 
    "travis_ci": true, 
    "github_project": "marshmallow-sqlalchemy", 
    "summary": "SQLAlchemy integration with the marshmallow (de)serialization library", 
    "split_keywords": [
        "sqlalchemy", 
        "marshmallow"
    ], 
    "author_email": "sloria1@gmail.com", 
    "urls": [
        {
            "has_sig": false, 
            "upload_time": "2018-03-08T01:09:09", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/a0/fe/b0bec7c3b40fb3f4956af457eefcfb9dbc74bb0632040f523a1608404da6/marshmallow-sqlalchemy-pk-0.13.2.tar.gz", 
            "md5_digest": "c4e681a1691b15c74cf60dc07ab11af6", 
            "downloads": 0, 
            "filename": "marshmallow-sqlalchemy-pk-0.13.2.tar.gz", 
            "packagetype": "sdist", 
            "path": "a0/fe/b0bec7c3b40fb3f4956af457eefcfb9dbc74bb0632040f523a1608404da6/marshmallow-sqlalchemy-pk-0.13.2.tar.gz", 
            "size": 38974
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}