Skip to main content

SQLAlchemy-JSONField

https://travis-ci.com/penguinolog/sqlalchemy_jsonfield.svg?branch=master https://coveralls.io/repos/github/penguinolog/sqlalchemy_jsonfield/badge.svg?branch=master https://img.shields.io/circleci/project/github/penguinolog/sqlalchemy_jsonfield.svg https://img.shields.io/pypi/v/sqlalchemy_jsonfield.svg https://img.shields.io/pypi/pyversions/sqlalchemy_jsonfield.svg https://img.shields.io/pypi/status/sqlalchemy_jsonfield.svg https://img.shields.io/github/license/penguinolog/sqlalchemy_jsonfield.svg https://img.shields.io/badge/code%20style-black-000000.svg

SQLALchemy JSONField implementation for storing dicts at SQL independently from JSON type support.

Why?

SqlAlchemy provides JSON field support for several database types (PostgreSQL and MySQL for now) and semi-working dict <-> JSON <-> VARCHAR example, but… In real scenarios we have tests on sqlite, production on MySQL/MariaDB/Percona/PostgreSQL and some of them (modern Oracle MySQL & PostgreSQL) support JSON, some of them (SQLite, Percona & MariaDB) requires data conversion to Text (not VARCHAR).

As addition, we have different levels of Unicode support on database and connector side, so we may be interested to switch JSON encoding between deployments.

Solution:

SQLALchemy JSONField has API with suport for automatic switch between native JSON and JSON encoded data, and encoding to JSON string can be enforced.

Pros:

  • Free software: Apache license

  • Open Source: https://github.com/penguinolog/sqlalchemy_jsonfield

  • Self-documented code: docstrings with types in comments

  • Uses native JSON by default, but allows to specify different library.

  • Support miltiple Python versions:

Python 3.5
Python 3.6
Python 3.7
Python 3.8
PyPy
PyPy3

Usage

Direct usage with MariaDB (example extracted from functional tests):

import sqlalchemy_jsonfield

class ExampleTable(Base):
    __tablename__ = table_name
    id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    row_name = sqlalchemy.Column(
        sqlalchemy.Unicode(64),
        unique=True,
    )
    json_record = sqlalchemy.Column(
        sqlalchemy_jsonfield.JSONField(
            # MariaDB does not support JSON for now
            enforce_string=True,
            # MariaDB connector requires additional parameters for correct UTF-8
            enforce_unicode=False
        ),
        nullable=False
    )

Usage with alternate JSON library:

import sqlalchemy_jsonfield
import ujson

class ExampleTable(Base):
    __tablename__ = table_name
    id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    row_name = sqlalchemy.Column(
        sqlalchemy.Unicode(64),
        unique=True,
    )
    json_record = sqlalchemy.Column(
        sqlalchemy_jsonfield.JSONField(
            enforce_string=True,
            enforce_unicode=False,
            json=ujson,  # Use ujson instead of standard json.
        ),
        nullable=False
    )

Usage on PostgreSQL/Oracle MySQL(modern version)/SQLite(testing) environments allows to set enforce_string=False and use native JSON fields.

Testing

The main test mechanism for the package sqlalchemy_jsonfield is using tox. Test environments available:

pep8
py35
py36
py37
py38
pypy3
pylint
docs

CI systems

For code checking several CI systems is used in parallel:

  1. Travis CI: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it’s publishes coverage on coveralls.

  2. coveralls: is used for coverage display.

  3. Circle CI: is used for functional tests at separate docker infrastructure. This CI used for HUGE tests.

CD system

Travis CI: is used for package delivery on PyPI.

Metadata

Release files for SQLAlchemy-JSONField 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SQLAlchemy-JSONField 0.9.0
File Size Uploaded Provenance Actions
SQLAlchemy-JSONField-0.9.0.tar.gz 32.2 kB Without provenance Details for SQLAlchemy-JSONField-0.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for SQLAlchemy-JSONField 0.9.0
File Interpreter ABI Platform Actions
SQLAlchemy_JSONField-0.9.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for SQLAlchemy_JSONField-0.9.0-py2.py3-none-any.whl

Total release size: 42.3 kB

Release files / SQLAlchemy-JSONField-0.9.0.tar.gz

Download URL SQLAlchemy-JSONField-0.9.0.tar.gz
Size 32.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1cb760abf186a97beb5acdfd47dc2f98829070f679a838869162cd7c0b447e0d
BLAKE2b-256 checksum
How to use checksums
f03e8e671d4d6ca1acf347f2be8cbecd6acc15e1d99833c6f466424167aa0fdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 PyPy/7.1.1beta

Release files / SQLAlchemy_JSONField-0.9.0-py2.py3-none-any.whl

Download URL SQLAlchemy_JSONField-0.9.0-py2.py3-none-any.whl
Size 10.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1abf295f7215c8f1c0b0d30d659f4372870fc83755874ef21cad7e2f2d6419ba
BLAKE2b-256 checksum
How to use checksums
d370f636dd6f9e6bd38e64ba398a24c717af141d9771ccfd79b174b989d5a624
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 PyPy/7.1.1beta

Security for SQLAlchemy-JSONField 0.9.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page