--- id: sqlalchemy-serializer version: "1.6.3" license: MIT license_treatment: permissive maintenance: active --- # sqlalchemy-serializer — Mixin for SQLAlchemy models serialization without pain License: permissive · Maintenance: active · Downloads: 164.0K/mo ## What it is and what it does SQLAlchemy-serializer is a mixin that adds a `.to_dict()` method to SQLAlchemy model instances, turning them into dictionaries suitable for JSON responses or data export. It handles nested relationships automatically, includes support for both traditional and modern SQLAlchemy 2.0 annotation styles, and offers fine-grained control over which fields to include or exclude via `rules`, `only`, and `exclude_values` parameters. The package is designed for developers who need simple model-to-dict conversion without the overhead of schema libraries like marshmallow. It supports custom serialization logic per column, timezone handling via pytz, recursion depth limits to prevent infinite loops, and the ability to include non-SQLAlchemy fields or method results in the output. Runtime dependencies are SQLAlchemy, psycopg2-binary, pytz, and setuptools. Use it for: - Convert SQLAlchemy model instances to dictionaries for JSON API responses without defining separate serialization schemas. - Exclude sensitive fields (passwords, tokens) from serialized output using negative rules or custom serializers. - Serialize nested relationships and foreign-key references in a single call with configurable depth limits. - Add computed or non-database fields to serialized output by including methods or properties in the rules. - Filter out null or empty values from the serialized dictionary to reduce payload size in API responses. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Adds a `.to_dict()` method to SQLAlchemy model instances, converting them to dictionaries with support for nested relationships, custom field rules, and timezone handling. Yes. The package is actively maintained, has no known vulnerabilities, uses a permissive MIT license, and solves a common problem—model serialization—with minimal dependencies and low install friction. It's well-suited for Flask/FastAPI applications and other projects where lightweight, ad-hoc model-to-dict conversion is needed. Install it if you want to avoid the boilerplate of schema libraries for straightforward serialization tasks. ## Install pip install sqlalchemy-serializer uv add sqlalchemy-serializer poetry add sqlalchemy-serializer ## Installing sqlalchemy-serializer Before you install: Low friction: pure Python wheel with four runtime dependencies (SQLAlchemy, psycopg2-binary, pytz, setuptools). Actively maintained with recent releases; last commit 2026-05-11 and 201 repository stars indicate steady upkeep. License in practice: MIT license (permissive) allows use in commercial and proprietary projects with minimal restrictions—include a copy of the license and attribute the original author. Quickstart: from sqlalchemy_serializer import SerializerMixin class MyModel(db.Model, SerializerMixin): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(256)) item = MyModel.query.first() result = item.to_dict() Requires Python 3.10 or later. Verify before relying: - Whether psycopg2-binary is required for all use cases or only when using PostgreSQL backends. - Performance characteristics when serializing deeply nested relationships or large model graphs. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 164.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags sqlalchemy model to dict, serialize sqlalchemy objects, sqlalchemy to json, sqlalchemy model serialization, convert sqlalchemy to dictionary, sqlalchemy mixin serializer, sqlalchemy json export, orm-serialization, json-export, rest-api [View on SkillFed](https://skillfed.io/packages/sqlalchemy-serializer) · [View on PyPI](https://pypi.org/project/sqlalchemy-serializer/)