SQLALchemy JSONField implementation for storing dicts at SQL
Project description
SQLAlchemy-JSONField
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 multiple Python versions:
Python 3.5 Python 3.6 Python 3.7 Python 3.8 Python 3.9 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:
Travis CI: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it’s publishes coverage on coveralls.
coveralls: is used for coverage display.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file SQLAlchemy-JSONField-1.0.0.tar.gz
.
File metadata
- Download URL: SQLAlchemy-JSONField-1.0.0.tar.gz
- Upload date:
- Size: 28.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 PyPy/7.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 766d0b25bdebf53f67ccfaf9975987f921965987b37bae3a95ba6e7855afe98b |
|
MD5 | bda8f14def88017d29de11786e7a8560 |
|
BLAKE2b-256 | 3ed0c3fd057b81c86bea679f980420d756793cc8cf76f88c0ef7e9572bdb88da |
File details
Details for the file SQLAlchemy_JSONField-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: SQLAlchemy_JSONField-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 PyPy/7.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db129c0e79f6b3c61ca88b340363e2cc2023a187a40b9992dfee33bc75c3a02c |
|
MD5 | a24d8a726222abbb472ed7ce201ce147 |
|
BLAKE2b-256 | 6d98ed56c228713cea8a0f71afb62d6fda82d3c8e6468d18e09030578f6f42ab |