METADATA 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. Metadata-Version: 2.1
  2. Name: SQLAlchemy-JSONField
  3. Version: 1.0.2
  4. Summary: SQLALchemy JSONField implementation for storing dicts at SQL
  5. Author-email: Alexey Stepanov <penguinolog@gmail.com>
  6. License: Apache-2.0
  7. Project-URL: Repository, https://github.com/penguinolog/sqlalchemy_jsonfield
  8. Project-URL: Bug Tracker, https://github.com/penguinolog/sqlalchemy_jsonfield/issues
  9. Keywords: sql,sqlalchemy,json,jsonfield,development
  10. Classifier: Development Status :: 4 - Beta
  11. Classifier: Intended Audience :: Developers
  12. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  13. Classifier: License :: OSI Approved :: Apache Software License
  14. Classifier: Programming Language :: Python :: 3
  15. Classifier: Programming Language :: Python :: 3.7
  16. Classifier: Programming Language :: Python :: 3.8
  17. Classifier: Programming Language :: Python :: 3.9
  18. Classifier: Programming Language :: Python :: 3.10
  19. Classifier: Programming Language :: Python :: 3.11
  20. Classifier: Programming Language :: Python :: 3.12
  21. Classifier: Programming Language :: Python :: Implementation :: CPython
  22. Classifier: Programming Language :: Python :: Implementation :: PyPy
  23. Requires-Python: >=3.7.0
  24. Description-Content-Type: text/x-rst
  25. License-File: LICENSE
  26. Requires-Dist: sqlalchemy
  27. SQLAlchemy-JSONField
  28. ====================
  29. .. image:: https://github.com/penguinolog/sqlalchemy_jsonfield/workflows/Python%20package/badge.svg
  30. :target: https://github.com/penguinolog/sqlalchemy_jsonfield/actions
  31. .. image:: https://img.shields.io/pypi/v/sqlalchemy_jsonfield.svg
  32. :target: https://pypi.python.org/pypi/sqlalchemy_jsonfield
  33. .. image:: https://img.shields.io/pypi/pyversions/sqlalchemy_jsonfield.svg
  34. :target: https://pypi.python.org/pypi/sqlalchemy_jsonfield
  35. .. image:: https://img.shields.io/pypi/status/sqlalchemy_jsonfield.svg
  36. :target: https://pypi.python.org/pypi/sqlalchemy_jsonfield
  37. .. image:: https://img.shields.io/github/license/penguinolog/sqlalchemy_jsonfield.svg
  38. :target: https://raw.githubusercontent.com/penguinolog/sqlalchemy_jsonfield/master/LICENSE
  39. .. image:: https://img.shields.io/badge/code%20style-black-000000.svg
  40. :target: https://github.com/ambv/black
  41. SQLALchemy JSONField implementation for storing dicts at SQL independently from JSON type support.
  42. Why?
  43. ----
  44. SqlAlchemy provides JSON field support for several database types (PostgreSQL and MySQL for now)
  45. and semi-working dict <-> JSON <-> VARCHAR example, but...
  46. In real scenarios we have tests on sqlite, production on MySQL/MariaDB/Percona/PostgreSQL
  47. and some of them (modern Oracle MySQL & PostgreSQL) support JSON,
  48. some of them (SQLite, Percona & MariaDB) requires data conversion to Text (not VARCHAR).
  49. As addition, we have different levels of Unicode support on database and connector side,
  50. so we may be interested to switch JSON encoding between deployments.
  51. .. note:: SQLite 3.9 supports JSON natively and SQLAlchemy can handle this.
  52. Solution:
  53. ---------
  54. SQLALchemy JSONField has API with suport for automatic switch between native JSON and JSON encoded data,
  55. and encoding to JSON string can be enforced.
  56. Pros:
  57. -----
  58. * Free software: Apache license
  59. * Open Source: https://github.com/penguinolog/sqlalchemy_jsonfield
  60. * Self-documented code: docstrings with types in comments
  61. * Uses native JSON by default, but allows to specify different library.
  62. * Support multiple Python versions
  63. Usage
  64. =====
  65. Direct usage with MariaDB (example extracted from functional tests):
  66. .. code-block:: python
  67. import sqlalchemy_jsonfield
  68. class ExampleTable(Base):
  69. __tablename__ = table_name
  70. id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
  71. row_name = sqlalchemy.Column(
  72. sqlalchemy.Unicode(64),
  73. unique=True,
  74. )
  75. json_record = sqlalchemy.Column(
  76. sqlalchemy_jsonfield.JSONField(
  77. # MariaDB does not support JSON for now
  78. enforce_string=True,
  79. # MariaDB connector requires additional parameters for correct UTF-8
  80. enforce_unicode=False
  81. ),
  82. nullable=False
  83. )
  84. Usage with alternate JSON library:
  85. .. code-block:: python
  86. import sqlalchemy_jsonfield
  87. import ujson
  88. class ExampleTable(Base):
  89. __tablename__ = table_name
  90. id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
  91. row_name = sqlalchemy.Column(
  92. sqlalchemy.Unicode(64),
  93. unique=True,
  94. )
  95. json_record = sqlalchemy.Column(
  96. sqlalchemy_jsonfield.JSONField(
  97. enforce_string=True,
  98. enforce_unicode=False,
  99. json=ujson, # Use ujson instead of standard json.
  100. ),
  101. nullable=False
  102. )
  103. Usage on PostgreSQL/Oracle MySQL(modern version)/SQLite(testing) environments allows to set `enforce_string=False`
  104. and use native JSON fields.
  105. Testing
  106. =======
  107. The main test mechanism for the package `sqlalchemy_jsonfield` is using `tox`.
  108. Available environments can be collected via `tox -l`
  109. CI systems
  110. ==========
  111. For code checking several CI systems is used in parallel:
  112. 1. `GitHub actions: <https://github.com/penguinolog/sqlalchemy_jsonfield/actions>`_ is used for checking: PEP8, pylint, bandit, installation possibility and unit tests.