quart-sqlalchemy


Namequart-sqlalchemy JSON
Version 3.0.4 PyPI version JSON
download
home_page
SummarySQLAlchemy for humans, with framework adapter for Quart.
upload_time2023-11-13 18:48:00
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Quart-SQLAlchemy
================

Quart-SQLAlchemy provides a simple wrapper for SQLAlchemy made for humans.  I've kept things as
simple as possible, abstracted much complexity, and implemented everything using the current
best practices recommended by the SQLAlchemy developers and targets version 2.0.x+.  As a
convenience, a framework adapter is provided for Quart, but the rest of this library is framework
agnostic.

The bundled SQLAlchemy object intentionally discards the use of scoped_session and it's async
counterpart.  With version 2.x+, it's expected that sessions are short lived and vanilla and
context managers are used for managing sesssion lifecycle.  Any operations that intend to change
state should open an explicit transaction using the context manager returned by session.begin().
This pattern of usage prevents problems like sessions being shared between processes, threads, or
tasks entirely, as opposed to the past conventions of mitigating this type of sharing.  Another
best practice is expecting any transaction to intermittently fail, and structuring your logic to
automatically perform retries.  You can find the retrying session context managers in the retry
module.

Installing
----------

Install and update using `pip`_:

.. code-block:: text

  $ pip install quart-sqlalchemy

.. _pip: https://pip.pypa.io/en/stable/getting-started/


Install the latest release with unreleased pytest-asyncio fixes:

.. code-block:: text

  $ pip install git+ssh://git@github.com/joeblackwaslike/quart-sqlalchemy.git#egg=quart_sqlalchemy

Install a wheel from our releases:

.. code-block:: text

  $ pip install https://github.com/joeblackwaslike/quart-sqlalchemy/releases/download/v3.0.1/quart_sqlalchemy-3.0.1-py3-none-any.whl


Add to requirements.txt:

.. code-block:: text

    quart-sqlalchemy @ https://github.com/joeblackwaslike/quart-sqlalchemy/releases/download/v3.0.1/quart_sqlalchemy-3.0.1-py3-none-any.whl


A Simple Example
----------------

.. code-block:: python

    import sqlalchemy as sa
    import sqlalchemy.orm
    from sqlalchemy.orm import Mapped, mapped_column
    from quart import Quart

    from quart_sqlalchemy import SQLAlchemyConfig
    from quart_sqlalchemy.framework import QuartSQLAlchemy

    app = Quart(__name__)

    db = QuartSQLAlchemy(
      config=SQLAlchemyConfig
          binds=dict(
              default=dict(
                  engine=dict(
                      url="sqlite:///",
                      echo=True,
                      connect_args=dict(check_same_thread=False),
                  ),
                  session=dict(
                      expire_on_commit=False,
                  ),
              )
          )
      ),
      app,
    )

    class User(db.Model)
        __tablename__ = "user"

        id: Mapped[int] = mapped_column(sa.Identity(), primary_key=True, autoincrement=True)
        name: Mapped[str] = mapped_column(default="default")

    db.create_all()
    
    with db.bind.Session() as s:
        with s.begin():
            user = User(username="example")
            s.add(user)
            s.flush()
            s.refresh(user)

        users = s.scalars(sa.select(User)).all()
    
    print(user, users)
    assert user in users
  
Contributing
------------

For guidance on setting up a development environment and how to make a
contribution to Quart-SQLAlchemy, see the `contributing guidelines`_.

.. _contributing guidelines: https://github.com/joeblackwaslike/quart-sqlalchemy/blob/main/CONTRIBUTING.rst

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "quart-sqlalchemy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Joe Black <me@joeblack.nyc>",
    "download_url": "https://files.pythonhosted.org/packages/4e/77/d3764f7c4d0a5abe692db68cbf0992a5766fe41c7b85ffa9af54a9bd1c52/quart_sqlalchemy-3.0.4.tar.gz",
    "platform": null,
    "description": "Quart-SQLAlchemy\n================\n\nQuart-SQLAlchemy provides a simple wrapper for SQLAlchemy made for humans.  I've kept things as\nsimple as possible, abstracted much complexity, and implemented everything using the current\nbest practices recommended by the SQLAlchemy developers and targets version 2.0.x+.  As a\nconvenience, a framework adapter is provided for Quart, but the rest of this library is framework\nagnostic.\n\nThe bundled SQLAlchemy object intentionally discards the use of scoped_session and it's async\ncounterpart.  With version 2.x+, it's expected that sessions are short lived and vanilla and\ncontext managers are used for managing sesssion lifecycle.  Any operations that intend to change\nstate should open an explicit transaction using the context manager returned by session.begin().\nThis pattern of usage prevents problems like sessions being shared between processes, threads, or\ntasks entirely, as opposed to the past conventions of mitigating this type of sharing.  Another\nbest practice is expecting any transaction to intermittently fail, and structuring your logic to\nautomatically perform retries.  You can find the retrying session context managers in the retry\nmodule.\n\nInstalling\n----------\n\nInstall and update using `pip`_:\n\n.. code-block:: text\n\n  $ pip install quart-sqlalchemy\n\n.. _pip: https://pip.pypa.io/en/stable/getting-started/\n\n\nInstall the latest release with unreleased pytest-asyncio fixes:\n\n.. code-block:: text\n\n  $ pip install git+ssh://git@github.com/joeblackwaslike/quart-sqlalchemy.git#egg=quart_sqlalchemy\n\nInstall a wheel from our releases:\n\n.. code-block:: text\n\n  $ pip install https://github.com/joeblackwaslike/quart-sqlalchemy/releases/download/v3.0.1/quart_sqlalchemy-3.0.1-py3-none-any.whl\n\n\nAdd to requirements.txt:\n\n.. code-block:: text\n\n    quart-sqlalchemy @ https://github.com/joeblackwaslike/quart-sqlalchemy/releases/download/v3.0.1/quart_sqlalchemy-3.0.1-py3-none-any.whl\n\n\nA Simple Example\n----------------\n\n.. code-block:: python\n\n    import sqlalchemy as sa\n    import sqlalchemy.orm\n    from sqlalchemy.orm import Mapped, mapped_column\n    from quart import Quart\n\n    from quart_sqlalchemy import SQLAlchemyConfig\n    from quart_sqlalchemy.framework import QuartSQLAlchemy\n\n    app = Quart(__name__)\n\n    db = QuartSQLAlchemy(\n      config=SQLAlchemyConfig\n          binds=dict(\n              default=dict(\n                  engine=dict(\n                      url=\"sqlite:///\",\n                      echo=True,\n                      connect_args=dict(check_same_thread=False),\n                  ),\n                  session=dict(\n                      expire_on_commit=False,\n                  ),\n              )\n          )\n      ),\n      app,\n    )\n\n    class User(db.Model)\n        __tablename__ = \"user\"\n\n        id: Mapped[int] = mapped_column(sa.Identity(), primary_key=True, autoincrement=True)\n        name: Mapped[str] = mapped_column(default=\"default\")\n\n    db.create_all()\n    \n    with db.bind.Session() as s:\n        with s.begin():\n            user = User(username=\"example\")\n            s.add(user)\n            s.flush()\n            s.refresh(user)\n\n        users = s.scalars(sa.select(User)).all()\n    \n    print(user, users)\n    assert user in users\n  \nContributing\n------------\n\nFor guidance on setting up a development environment and how to make a\ncontribution to Quart-SQLAlchemy, see the `contributing guidelines`_.\n\n.. _contributing guidelines: https://github.com/joeblackwaslike/quart-sqlalchemy/blob/main/CONTRIBUTING.rst\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "SQLAlchemy for humans, with framework adapter for Quart.",
    "version": "3.0.4",
    "project_urls": {
        "Bug tracker": "https://github.com/joeblackwaslike/quart-sqlalchemy/issues",
        "Homepage": "https://github.com/joeblackwaslike/quart-sqlalchemy"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e9d2f4a6711608b666b7538150ab4569c0058fbfdc068e605a918719791e9932",
                "md5": "0909f391da174db425e43298940f0816",
                "sha256": "d262542fd83780917bd30bf7b6f33b291784a8a796e9962cf87c5aff7368c110"
            },
            "downloads": -1,
            "filename": "quart_sqlalchemy-3.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0909f391da174db425e43298940f0816",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 2992117,
            "upload_time": "2023-11-13T18:47:57",
            "upload_time_iso_8601": "2023-11-13T18:47:57.528172Z",
            "url": "https://files.pythonhosted.org/packages/e9/d2/f4a6711608b666b7538150ab4569c0058fbfdc068e605a918719791e9932/quart_sqlalchemy-3.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e77d3764f7c4d0a5abe692db68cbf0992a5766fe41c7b85ffa9af54a9bd1c52",
                "md5": "fc9e19f44bb8dce9aa8e6b2316d5545f",
                "sha256": "302f9da74ddd86fc02cf83d5a48d608796cd728e3c6892d98f992e0d49da0121"
            },
            "downloads": -1,
            "filename": "quart_sqlalchemy-3.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "fc9e19f44bb8dce9aa8e6b2316d5545f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 2115378,
            "upload_time": "2023-11-13T18:48:00",
            "upload_time_iso_8601": "2023-11-13T18:48:00.263013Z",
            "url": "https://files.pythonhosted.org/packages/4e/77/d3764f7c4d0a5abe692db68cbf0992a5766fe41c7b85ffa9af54a9bd1c52/quart_sqlalchemy-3.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-13 18:48:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "joeblackwaslike",
    "github_project": "quart-sqlalchemy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "quart-sqlalchemy"
}
        
Elapsed time: 0.32861s