All Projects → marshmallow-code → Marshmallow Sqlalchemy

marshmallow-code / Marshmallow Sqlalchemy

Licence: mit
SQLAlchemy integration with marshmallow

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Marshmallow Sqlalchemy

Gino
GINO Is Not ORM - a Python asyncio ORM on SQLAlchemy core.
Stars: ✭ 2,299 (+439.67%)
Mutual labels:  hacktoberfest, sqlalchemy
Environs
simplified environment variable parsing
Stars: ✭ 631 (+48.12%)
Mutual labels:  marshmallow, hacktoberfest
Factory boy
A test fixtures replacement for Python
Stars: ✭ 2,712 (+536.62%)
Mutual labels:  hacktoberfest, sqlalchemy
Full Stack
Full stack, modern web application generator. Using Flask, PostgreSQL DB, Docker, Swagger, automatic HTTPS and more.
Stars: ✭ 451 (+5.87%)
Mutual labels:  marshmallow, sqlalchemy
Hobbit Core
A flask project generator.
Stars: ✭ 49 (-88.5%)
Mutual labels:  marshmallow, sqlalchemy
Tedivms Flask
Flask starter app with celery, bootstrap, and docker environment
Stars: ✭ 142 (-66.67%)
Mutual labels:  hacktoberfest, sqlalchemy
Flask Rest Jsonapi
Flask extension to build REST APIs around JSONAPI 1.0 specification.
Stars: ✭ 566 (+32.86%)
Mutual labels:  marshmallow, sqlalchemy
Indico
Indico - A feature-rich event management system, made @ CERN, the place where the Web was born.
Stars: ✭ 1,160 (+172.3%)
Mutual labels:  hacktoberfest, sqlalchemy
Python Api Development Fundamentals
Develop a full-stack web application with Python and Flask
Stars: ✭ 44 (-89.67%)
Mutual labels:  marshmallow, sqlalchemy
Apispec
A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification)..
Stars: ✭ 831 (+95.07%)
Mutual labels:  marshmallow, hacktoberfest
Flask Marshmallow
Flask + marshmallow for beautiful APIs
Stars: ✭ 666 (+56.34%)
Mutual labels:  marshmallow, sqlalchemy
Marshmallow Oneofschema
Marshmallow library extension that allows schema (de)multiplexing
Stars: ✭ 94 (-77.93%)
Mutual labels:  marshmallow, hacktoberfest
Webargs
A friendly library for parsing HTTP request arguments, with built-in support for popular web frameworks, including Flask, Django, Bottle, Tornado, Pyramid, webapp2, Falcon, and aiohttp.
Stars: ✭ 1,145 (+168.78%)
Mutual labels:  marshmallow, hacktoberfest
flask-rest-api
This program shows how to set up a flaskrestapi with postgre db, blueprint, sqlalchemy, marshmallow, wsgi, unittests
Stars: ✭ 28 (-93.43%)
Mutual labels:  sqlalchemy, marshmallow
Edxposed
Elder driver Xposed Framework.
Stars: ✭ 4,458 (+946.48%)
Mutual labels:  hacktoberfest
Lavalink
Standalone audio sending node based on Lavaplayer.
Stars: ✭ 420 (-1.41%)
Mutual labels:  hacktoberfest
Rustup
The Rust toolchain installer
Stars: ✭ 4,394 (+931.46%)
Mutual labels:  hacktoberfest
Bunit
A testing library for Blazor Components. You can easily define components under test in C# or Razor syntax and verify outcome using semantic HTML diffing/comparison logic. You can easily interact with and inspect components, trigger event handlers, provide cascading values, inject services, mock IJSRuntime, and perform snapshot testing.
Stars: ✭ 415 (-2.58%)
Mutual labels:  hacktoberfest
Imgcat
a tool to output images as RGB ANSI graphics on the terminal
Stars: ✭ 425 (-0.23%)
Mutual labels:  hacktoberfest
Ngx Scanner
Angular (2+) QR code, Barcode, DataMatrix, scanner component using ZXing.
Stars: ✭ 420 (-1.41%)
Mutual labels:  hacktoberfest

marshmallow-sqlalchemy


|pypi-package| |build-status| |docs| |marshmallow3| |black|

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, nullable=False)

    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 SQLAlchemySchema, auto_field


class AuthorSchema(SQLAlchemySchema):
    class Meta:
        model = Author
        load_instance = True  # Optional: deserialize to model instances

    id = auto_field()
    name = auto_field()
    books = auto_field()


class BookSchema(SQLAlchemySchema):
    class Meta:
        model = Book
        load_instance = True

    id = auto_field()
    title = auto_field()
    author_id = auto_field()

You can automatically generate fields for a model's columns using SQLAlchemyAutoSchema. The following schema classes are equivalent to the above.

.. code-block:: python

from marshmallow_sqlalchemy import SQLAlchemyAutoSchema


class AuthorSchema(SQLAlchemyAutoSchema):
    class Meta:
        model = Author
        include_relationships = True
        load_instance = True


class BookSchema(SQLAlchemyAutoSchema):
    class Meta:
        model = Book
        include_fk = True
        load_instance = True

Make sure to declare Models before instantiating Schemas. Otherwise sqlalchemy.orm.configure_mappers() <https://docs.sqlalchemy.org/en/latest/orm/mapping_api.html>_ will run too soon and fail.

(De)serialize your data

.. code-block:: python

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

dump_data = author_schema.dump(author)
print(dump_data)
# {'id': 1, 'name': 'Chuck Paluhniuk', 'books': [1]}

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

Get it now

::

pip install -U marshmallow-sqlalchemy

Requires Python >= 3.6, marshmallow >= 3.0.0, and SQLAlchemy >= 1.2.0.

Documentation

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

Project Links

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://badgen.net/pypi/v/marshmallow-sqlalchemy :target: https://pypi.org/project/marshmallow-sqlalchemy/ :alt: Latest version .. |build-status| image:: https://dev.azure.com/sloria/sloria/_apis/build/status/marshmallow-code.marshmallow-sqlalchemy?branchName=dev :target: https://dev.azure.com/sloria/sloria/_build/latest?definitionId=10&branchName=dev :alt: Build status .. |docs| image:: https://readthedocs.org/projects/marshmallow-sqlalchemy/badge/ :target: http://marshmallow-sqlalchemy.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 .. |black| image:: https://badgen.net/badge/code%20style/black/000 :target: https://github.com/ambv/black :alt: code style: black

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].