marshmallow-sqlalchemy
Homepage: https://marshmallow-sqlalchemy.readthedocs.io/
SQLAlchemy integration with the marshmallow (de)serialization library.
Declare your models
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
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
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).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
License
MIT licensed. See the bundled LICENSE file for more details.
Metadata
Release files for marshmallow-muffin-sqlalchemy 0.30.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| marshmallow-muffin-sqlalchemy-0.30.0.tar.gz | 11.4 kB | Without provenance | Details for marshmallow-muffin-sqlalchemy-0.30.0.tar.gz |
Release files / marshmallow-muffin-sqlalchemy-0.30.0.tar.gz
| Download URL | marshmallow-muffin-sqlalchemy-0.30.0.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
749a8e96e4450df775fc657ec1ae0e251a62dc975118d8006fc8159ed93a6e1a
|
|
BLAKE2b-256 checksum How to use checksums |
9243bf6d9d2fbf4a3f0ff8504be54eacd1d82cb538ae34d2350d0cbf89626370
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.16 CPython/3.7.1 Linux/4.15.0-1028-gcp
|
Security for marshmallow-muffin-sqlalchemy 0.30.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.