skillfed

SQLAlchemy-JSONField

SQLALchemy JSONField implementation for storing dicts at SQL

sqlalchemy-jsonfield v1.0.3 6.0M downloads/30d#1,982 on PyPI24
Permissive license Apache-2.0 Active released

What it is and what it does

SQLAlchemy-JSONField is a custom column type that abstracts away database-specific JSON handling differences. It lets you store Python dictionaries as JSON in your SQLAlchemy models while automatically choosing between native JSON support (PostgreSQL, modern MySQL, SQLite 3.9+) and text-encoded fallback (MariaDB, Percona, older SQLite). The package handles encoding/decoding transparently and lets you swap JSON libraries (e.g., ujson instead of the standard library json) or enforce string encoding when your database connector has Unicode limitations.

The main problem it solves is the fragmentation across test and production environments: you might test on SQLite but deploy on MySQL or PostgreSQL, and each has different JSON capabilities. Rather than writing conditional logic in your models, you define the field once with optional parameters like `enforce_string` and `enforce_unicode`, and the package adapts to whatever database is actually running.

Use it for:

  • Store semi-structured data (nested dicts, lists) in SQLite during testing, then use native JSON in PostgreSQL production without code changes.
  • Work around MariaDB's lack of native JSON support by automatically encoding to text while managing Unicode correctly.
  • Use a faster JSON library like ujson for serialization/deserialization by passing it to the JSONField constructor.
  • Migrate gradually from text-encoded JSON to native JSON as database versions are upgraded, without rewriting model definitions.
  • Support multiple database backends in a single codebase where some have JSON and others require text fallback.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides a SQLAlchemy column type for storing dictionaries as JSON, with automatic fallback to text encoding for databases that lack native JSON support.

Yes. The package solves a real cross-database compatibility problem with low install friction (one dependency), active maintenance, no known vulnerabilities, and permissive licensing. It's useful if you need to store JSON-like data across heterogeneous database environments or want to swap JSON libraries. Skip it if you're locked into a single database with native JSON support and don't need encoding flexibility.

Install

sqlalchemy-jsonfield on PyPI

pip

pip install sqlalchemy-jsonfield

uv

uv add sqlalchemy-jsonfield

poetry

poetry add sqlalchemy-jsonfield

Installing SQLAlchemy-JSONField

Before you install

Low friction: single runtime dependency on sqlalchemy, wheel distribution available. Active maintenance with recent release (95 days ago) and ongoing repository activity.

License in practice

Apache-2.0 permissive license allows commercial and private use with minimal restrictions.

Quickstart

import sqlalchemy_jsonfield
import sqlalchemy

class ExampleTable(Base):
    __tablename__ = 'example'
    id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    json_record = sqlalchemy.Column(
        sqlalchemy_jsonfield.JSONField(enforce_string=True),
        nullable=False
    )

Requires Python 3.9 or later; sqlalchemy must be installed as a runtime dependency.

Verify before relying

  • Whether the package works with SQLAlchemy 2.0+ (version constraint not specified in fact sheet)
  • Performance characteristics when handling large JSON documents across different database backends

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (>=3.9.0)
Install friction low — pure-Python wheel
Runtime dependencies 1 — sqlalchemy
Maintenance actively maintained — 95 days since the last release
Last repo commit
First released
Downloads 6,024,426/month — #1,982 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: sqlalchemy_jsonfield-1.0.3-py3-none-any.whl

Keywords: sql, sqlalchemy, json, jsonfield, development

Development Status :: 4 - BetaIntended Audience :: DevelopersProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Libraries :: Python Modules

Tags

sqlalchemy json fieldstore dict in databasejson column sqlalchemycross-database json storagesqlite mysql json compatibilitysqlalchemy text json fallback
sqlalchemy-extensioncross-database-compat

More Python Modules packages