<commit_before>.. module:: dictalchemy

Dictalchemy
===========

Dictalchemy adds :func:`utils.asdict` and :func:`utils.fromdict` methods to `SQLAlchemy <http://www.sqlalchemy.org/>`_ declarative models.

Currently this works with synonyms and simple relationships as one-to-many and many-to-many. Relationships can be followed in many levels.

The only collections currently supported is `sqlalchemy.orm.collections.InstrumentedList` and `sqlalchemy.orm.collections.MappedCollection`.

Using DictableModel
-------------------

:class:`classes.DictableModel` can be used as base class for `declarative_base` or as a mixin for a declarative class.

Example usage::

    from dictalchemy import DictableModel
    from slqlachemy.ext.declarative import declarative_base
    Base = declarative_base(cls=DictableModel)

Using make_class_dictable()
---------------------------

This method can be run on existing classes to make them dictable.

Example::

    Base = declarative_base()
    make_class_dictable(Base)

Default values
--------------

Default values are defined in :mod:`dictalchemy.constants`.

Using asdict()<commit_msg>Updated documentation regarding relations<commit_after>.. module:: dictalchemy

Dictalchemy
===========

Dictalchemy adds :func:`utils.asdict` and :func:`utils.fromdict` methods to `SQLAlchemy <http://www.sqlalchemy.org/>`_ declarative models.

Currently this works with synonyms and simple relationships as one-to-many and many-to-many. Relationships can be followed in many levels.

Any collection that inherits from `dict` or `list` is supported together with :class:`sqlalchemy.orm.dynamic.AppenderMixin` and :class:`sqlalchemy.orm.query.Query`.

Using DictableModel
-------------------

:class:`classes.DictableModel` can be used as base class for `declarative_base` or as a mixin for a declarative class.

Example usage::

    from dictalchemy import DictableModel
    from slqlachemy.ext.declarative import declarative_base
    Base = declarative_base(cls=DictableModel)

Using make_class_dictable()
---------------------------

This method can be run on existing classes to make them dictable.

Example::

    Base = declarative_base()
    make_class_dictable(Base)

Default values
--------------

Default values are defined in :mod:`dictalchemy.constants`.

Using asdict()
{'fraction_non_alphanumeric': 0.13333333333333333, 'fraction_numerical': 0.0, 'mean_word_length': 3.8755274261603376, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6679298', 'n_tokens_mistral': 669, 'n_tokens_neox': 642, 'n_words': 212}