{"id":13935779,"url":"https://github.com/marshmallow-code/marshmallow-sqlalchemy","last_synced_at":"2025-05-13T18:18:40.457Z","repository":{"id":31065697,"uuid":"34624554","full_name":"marshmallow-code/marshmallow-sqlalchemy","owner":"marshmallow-code","description":"SQLAlchemy integration with marshmallow","archived":false,"fork":false,"pushed_at":"2025-05-06T19:51:13.000Z","size":765,"stargazers_count":574,"open_issues_count":13,"forks_count":98,"subscribers_count":18,"default_branch":"dev","last_synced_at":"2025-05-06T20:38:32.295Z","etag":null,"topics":["marshmallow","python","sqlalchemy"],"latest_commit_sha":null,"homepage":"https://marshmallow-sqlalchemy.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marshmallow-code.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-04-26T18:16:28.000Z","updated_at":"2025-05-06T19:51:15.000Z","dependencies_parsed_at":"2023-11-17T07:33:57.764Z","dependency_job_id":"3c20453d-8638-4343-a511-eed43d02c76d","html_url":"https://github.com/marshmallow-code/marshmallow-sqlalchemy","commit_stats":{"total_commits":598,"total_committers":54,"mean_commits":"11.074074074074074","dds":0.5568561872909699,"last_synced_commit":"1330b08b41bf3c7e6b849cfff843f0942bdb7dce"},"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marshmallow-code%2Fmarshmallow-sqlalchemy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marshmallow-code%2Fmarshmallow-sqlalchemy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marshmallow-code%2Fmarshmallow-sqlalchemy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marshmallow-code%2Fmarshmallow-sqlalchemy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marshmallow-code","download_url":"https://codeload.github.com/marshmallow-code/marshmallow-sqlalchemy/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253610882,"owners_count":21935775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["marshmallow","python","sqlalchemy"],"created_at":"2024-08-07T23:02:05.474Z","updated_at":"2025-05-13T18:18:40.140Z","avatar_url":"https://github.com/marshmallow-code.png","language":"Python","readme":"**********************\nmarshmallow-sqlalchemy\n**********************\n\n|pypi-package| |build-status| |docs| |marshmallow-support|\n\nHomepage: https://marshmallow-sqlalchemy.readthedocs.io/\n\n`SQLAlchemy \u003chttp://www.sqlalchemy.org/\u003e`_ integration with the  `marshmallow \u003chttps://marshmallow.readthedocs.io/en/latest/\u003e`_ (de)serialization library.\n\n\nDeclare your models\n===================\n\n.. code-block:: python\n\n    import sqlalchemy as sa\n    from sqlalchemy.orm import (\n        DeclarativeBase,\n        backref,\n        relationship,\n        sessionmaker,\n    )\n\n    from marshmallow_sqlalchemy import SQLAlchemySchema, auto_field\n\n    engine = sa.create_engine(\"sqlite:///:memory:\")\n    Session = sessionmaker(engine)\n\n\n    class Base(DeclarativeBase):\n        pass\n\n\n    class Author(Base):\n        __tablename__ = \"authors\"\n        id = sa.Column(sa.Integer, primary_key=True)\n        name = sa.Column(sa.String, nullable=False)\n\n        def __repr__(self):\n            return f\"\u003cAuthor(name={self.name!r})\u003e\"\n\n\n    class Book(Base):\n        __tablename__ = \"books\"\n        id = sa.Column(sa.Integer, primary_key=True)\n        title = sa.Column(sa.String)\n        author_id = sa.Column(sa.Integer, sa.ForeignKey(\"authors.id\"))\n        author = relationship(\"Author\", backref=backref(\"books\"))\n\n\n    Base.metadata.create_all(engine)\n\n.. start elevator-pitch\n\nGenerate marshmallow schemas\n============================\n\n.. code-block:: python\n\n    from marshmallow_sqlalchemy import SQLAlchemySchema, auto_field\n\n\n    class AuthorSchema(SQLAlchemySchema):\n        class Meta:\n            model = Author\n            load_instance = True  # Optional: deserialize to model instances\n\n        id = auto_field()\n        name = auto_field()\n        books = auto_field()\n\n\n    class BookSchema(SQLAlchemySchema):\n        class Meta:\n            model = Book\n            load_instance = True\n\n        id = auto_field()\n        title = auto_field()\n        author_id = auto_field()\n\nYou can automatically generate fields for a model's columns using `SQLAlchemyAutoSchema`.\nThe following schema classes are equivalent to the above.\n\n.. code-block:: python\n\n    from marshmallow_sqlalchemy import SQLAlchemyAutoSchema\n\n\n    class AuthorSchema(SQLAlchemyAutoSchema):\n        class Meta:\n            model = Author\n            include_relationships = True\n            load_instance = True\n\n\n    class BookSchema(SQLAlchemyAutoSchema):\n        class Meta:\n            model = Book\n            include_fk = True\n            load_instance = True\n\n\nMake sure to declare `Models` before instantiating `Schemas`. Otherwise `sqlalchemy.orm.configure_mappers() \u003chttps://docs.sqlalchemy.org/en/latest/orm/mapping_api.html\u003e`_ will run too soon and fail.\n\n(De)serialize your data\n=======================\n\n.. code-block:: python\n\n    author = Author(name=\"Chuck Paluhniuk\")\n    author_schema = AuthorSchema()\n    book = Book(title=\"Fight Club\", author=author)\n\n    with Session() as session:\n        session.add(author)\n        session.add(book)\n        session.commit()\n\n        dump_data = author_schema.dump(author)\n        print(dump_data)\n        # {'id': 1, 'name': 'Chuck Paluhniuk', 'books': [1]}\n\n    with Session() as session:\n        load_data = author_schema.load(dump_data, session=session)\n        print(load_data)\n        # \u003cAuthor(name='Chuck Paluhniuk')\u003e\n\nGet it now\n==========\n\n.. code-block:: shell-session\n\n   $ pip install -U marshmallow-sqlalchemy\n\n\nRequires Python \u003e= 3.9, marshmallow \u003e= 3.18.0, and SQLAlchemy \u003e= 1.4.40.\n\n.. end elevator-pitch\n\nDocumentation\n=============\n\nDocumentation is available at https://marshmallow-sqlalchemy.readthedocs.io/ .\n\nProject links\n=============\n\n- Docs: https://marshmallow-sqlalchemy.readthedocs.io/\n- Changelog: https://marshmallow-sqlalchemy.readthedocs.io/en/latest/changelog.html\n- Contributing Guidelines: https://marshmallow-sqlalchemy.readthedocs.io/en/latest/contributing.html\n- PyPI: https://pypi.python.org/pypi/marshmallow-sqlalchemy\n- Issues: https://github.com/marshmallow-code/marshmallow-sqlalchemy/issues\n\nLicense\n=======\n\nMIT licensed. See the bundled `LICENSE \u003chttps://github.com/marshmallow-code/marshmallow-sqlalchemy/blob/dev/LICENSE\u003e`_ file for more details.\n\n\n.. |pypi-package| image:: https://badgen.net/pypi/v/marshmallow-sqlalchemy\n    :target: https://pypi.org/project/marshmallow-sqlalchemy/\n    :alt: Latest version\n.. |build-status| image:: https://github.com/marshmallow-code/marshmallow-sqlalchemy/actions/workflows/build-release.yml/badge.svg\n    :target: https://github.com/marshmallow-code/marshmallow-sqlalchemy/actions/workflows/build-release.yml\n    :alt: Build status\n.. |docs| image:: https://readthedocs.org/projects/marshmallow-sqlalchemy/badge/\n   :target: http://marshmallow-sqlalchemy.readthedocs.io/\n   :alt: Documentation\n.. |marshmallow-support| image:: https://badgen.net/badge/marshmallow/3,4?list=1\n    :target: https://marshmallow.readthedocs.io/en/latest/upgrading.html\n    :alt: marshmallow 3|4 compatible\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarshmallow-code%2Fmarshmallow-sqlalchemy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarshmallow-code%2Fmarshmallow-sqlalchemy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarshmallow-code%2Fmarshmallow-sqlalchemy/lists"}