marshmallow-sqlalchemy
SQLAlchemy integration with the marshmallow (de)serialization library
What it is and what it does
marshmallow-sqlalchemy bridges SQLAlchemy ORM models and the marshmallow serialization library, letting you define schemas that automatically map database columns and relationships to serializable fields. Instead of writing field definitions by hand, you declare a schema class pointing to your SQLAlchemy model, and the library generates the fields for you—optionally including relationships and foreign keys. You can then use the schema to dump model instances to dictionaries (for JSON APIs) or load dictionaries back into model instances.
The package handles the common pattern of building REST APIs or other services that need to convert between database objects and wire formats. It integrates with SQLAlchemy sessions to manage object loading and validation, and supports both explicit field declaration (auto_field) and full automatic schema generation (SQLAlchemyAutoSchema). The library is lightweight, with no dependencies beyond marshmallow and SQLAlchemy themselves.
Use it for:
- Build REST APIs that serialize SQLAlchemy models to JSON responses and validate incoming request data
- Generate API documentation schemas automatically from your database model definitions
- Validate and deserialize incoming data directly into ORM instances within a session
- Export database records to JSON or other formats for reporting or data migration
- Decouple your API contract from your internal model structure using schema field customization
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates marshmallow schemas from SQLAlchemy models to serialize and deserialize database objects to and from JSON or other formats.
Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and solves a standard problem in database-backed applications. It's widely used (top 5000 on PyPI) and permissively licensed. Install it if you're building APIs or services that need to serialize SQLAlchemy models.
Install
marshmallow-sqlalchemy on PyPI
pip
pip install marshmallow-sqlalchemyuv
uv add marshmallow-sqlalchemypoetry
poetry add marshmallow-sqlalchemyInstalling marshmallow-sqlalchemy
Before you install
Low friction: pure Python wheel with only two runtime dependencies (marshmallow and SQLAlchemy). Actively maintained with recent commits and releases spanning since 2015.
License in practice
MIT licensed under permissive terms, allowing use in commercial and proprietary projects with minimal restrictions.
Quickstart
pip install marshmallow-sqlalchemy
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
class AuthorSchema(SQLAlchemyAutoSchema):
class Meta:
model = Author
load_instance = True
schema = AuthorSchema()
author_dict = schema.dump(author_instance)
author_obj = schema.load(author_dict, session=db_session)
Requires Python >= 3.10, marshmallow >= 3.18.0, and SQLAlchemy >= 1.4.40. Models must be declared before schemas are instantiated.
Verify before relying
- Whether auto-generated schemas handle all SQLAlchemy column types and relationships correctly
- Performance characteristics when serializing large result sets or deeply nested relationships
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — marshmallow, SQLAlchemy |
| Maintenance | actively maintained — 135 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 12,176,068/month — #1,337 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: marshmallow_sqlalchemy-1.5.0-py3-none-any.whl
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
marshmallow-mongoengineGenerates marshmallow schemas automatically…
permissive · top 15,000 on PyPI
sqlalchemy-serializerAdds a `.to_dict()` method to SQLAlchemy model…
permissive · top 15,000 on PyPI
marshmallowMarshmallow converts complex Python objects to…
permissive · top 1,000 on PyPI
marshmallow-jsonapiProduces JSON API 1.0-compliant output from…
permissive · top 15,000 on PyPI
flask-marshmallowFlask-Marshmallow integrates Flask and…
permissive · top 5,000 on PyPI
sqlalchemy-reprAdds automatic, human-readable repr() output to…
unclear · top 15,000 on PyPI
amundsen-commonAmundsen Common provides shared utilities and…
unclear · top 15,000 on PyPI
graphene-sqlalchemyGraphene-SQLAlchemy exposes SQLAlchemy database…
permissive · top 15,000 on PyPI
marshmallow-jsonschemaConverts marshmallow schemas into JSON Schema…
permissive · top 5,000 on PyPI
marshmallow-unionAdds union field support to marshmallow,…
permissive · top 5,000 on PyPI