aiohttp-sqlalchemy


Nameaiohttp-sqlalchemy JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://pypi.org/project/aiohttp-sqlalchemy/
SummarySQLAlchemy 2.0 support for aiohttp.
upload_time2024-12-06 04:26:36
maintainerRuslan Ilyasovich Gilfanov
docs_urlNone
authorRuslan Ilyasovich Gilfanov
requires_python<4.0,>=3.9
licenseMIT
keywords aiohttp sqlalchemy asyncio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ==================
aiohttp-sqlalchemy
==================
|ReadTheDocs| |PyPI release| |License| |Python versions| |PyPI downloads| |GitHub CI|

.. |ReadTheDocs| image:: https://readthedocs.org/projects/aiohttp-sqlalchemy/badge/?version=latest
  :target: https://aiohttp-sqlalchemy.readthedocs.io/en/latest/?badge=latest
  :alt: Read The Docs build

.. |PyPI release| image:: https://badge.fury.io/py/aiohttp-sqlalchemy.svg
  :target: https://pypi.org/project/aiohttp-sqlalchemy/
  :alt: Release

.. |PyPI downloads| image:: https://static.pepy.tech/personalized-badge/aiohttp-sqlalchemy?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Downloads
  :target: https://pepy.tech/project/aiohttp-sqlalchemy
  :alt: PyPI downloads count

.. |Python versions| image:: https://img.shields.io/badge/Python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue
  :target: https://pypi.org/project/aiohttp-sqlalchemy/
  :alt: Python version support

.. |License| image:: https://img.shields.io/badge/License-MIT-green
  :target: https://github.com/ri-gilfanov/aiohttp-sqlalchemy/blob/master/LICENSE
  :alt: MIT License

.. |GitHub CI| image:: https://github.com/ri-gilfanov/aiohttp-sqlalchemy/actions/workflows/ci.yml/badge.svg?branch=master
  :target: https://github.com/ri-gilfanov/aiohttp-sqlalchemy/actions/workflows/ci.yml
  :alt: GitHub continuous integration

`SQLAlchemy 2.0 <https://www.sqlalchemy.org/>`_ support for `AIOHTTP
<https://docs.aiohttp.org/>`_.

The library provides the next features:

* initializing asynchronous sessions through a middlewares;
* initializing asynchronous sessions through a decorators;
* simple access to one asynchronous session by default key;
* preventing attributes from being expired after commit by default;
* support different types of request handlers;
* support nested applications.


Documentation
-------------
https://aiohttp-sqlalchemy.readthedocs.io


Installation
------------
::

    pip install aiohttp-sqlalchemy


Simple example
--------------
Install ``aiosqlite`` for work with sqlite3: ::

  pip install aiosqlite

Copy and paste this code in a file and run:

.. code-block:: python

  from datetime import datetime

  import sqlalchemy as sa
  from aiohttp import web
  from sqlalchemy import orm

  import aiohttp_sqlalchemy as ahsa


  class Base(orm.DeclarativeBase): ...


  class MyModel(Base):
      __tablename__ = "my_table"

      pk = sa.Column(sa.Integer, primary_key=True)
      timestamp = sa.Column(sa.DateTime(), default=datetime.now)


  async def main(request):
      sa_session = aiohttp_sqlalchemy.get_session(request)

      async with sa_session.begin():
          sa_session.add(MyModel())
          result = await sa_session.execute(sa.select(MyModel))
          result = result.scalars()

      data = {instance.pk: instance.timestamp.isoformat() for instance in result}
      return web.json_response(data)


  async def app_factory():
      app = web.Application()

      aiohttp_sqlalchemy.setup(
          app,
          [
              aiohttp_sqlalchemy.bind("sqlite+aiosqlite:///"),
          ],
      )
      await aiohttp_sqlalchemy.init_db(app, Base.metadata)

      app.add_routes([web.get("/", main)])
      return app


  if __name__ == "__main__":
      web.run_app(app_factory(), port=8087)

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/aiohttp-sqlalchemy/",
    "name": "aiohttp-sqlalchemy",
    "maintainer": "Ruslan Ilyasovich Gilfanov",
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": "ri.gilfanov@yandex.ru",
    "keywords": "aiohttp, sqlalchemy, asyncio",
    "author": "Ruslan Ilyasovich Gilfanov",
    "author_email": "ri.gilfanov@yandex.ru",
    "download_url": "https://files.pythonhosted.org/packages/4a/2c/9567c4ff890f7d3bf248727bdd7911c867084b77927568fa3f8b64e4b04f/aiohttp_sqlalchemy-1.1.0.tar.gz",
    "platform": null,
    "description": "==================\naiohttp-sqlalchemy\n==================\n|ReadTheDocs| |PyPI release| |License| |Python versions| |PyPI downloads| |GitHub CI|\n\n.. |ReadTheDocs| image:: https://readthedocs.org/projects/aiohttp-sqlalchemy/badge/?version=latest\n  :target: https://aiohttp-sqlalchemy.readthedocs.io/en/latest/?badge=latest\n  :alt: Read The Docs build\n\n.. |PyPI release| image:: https://badge.fury.io/py/aiohttp-sqlalchemy.svg\n  :target: https://pypi.org/project/aiohttp-sqlalchemy/\n  :alt: Release\n\n.. |PyPI downloads| image:: https://static.pepy.tech/personalized-badge/aiohttp-sqlalchemy?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Downloads\n  :target: https://pepy.tech/project/aiohttp-sqlalchemy\n  :alt: PyPI downloads count\n\n.. |Python versions| image:: https://img.shields.io/badge/Python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue\n  :target: https://pypi.org/project/aiohttp-sqlalchemy/\n  :alt: Python version support\n\n.. |License| image:: https://img.shields.io/badge/License-MIT-green\n  :target: https://github.com/ri-gilfanov/aiohttp-sqlalchemy/blob/master/LICENSE\n  :alt: MIT License\n\n.. |GitHub CI| image:: https://github.com/ri-gilfanov/aiohttp-sqlalchemy/actions/workflows/ci.yml/badge.svg?branch=master\n  :target: https://github.com/ri-gilfanov/aiohttp-sqlalchemy/actions/workflows/ci.yml\n  :alt: GitHub continuous integration\n\n`SQLAlchemy 2.0 <https://www.sqlalchemy.org/>`_ support for `AIOHTTP\n<https://docs.aiohttp.org/>`_.\n\nThe library provides the next features:\n\n* initializing asynchronous sessions through a middlewares;\n* initializing asynchronous sessions through a decorators;\n* simple access to one asynchronous session by default key;\n* preventing attributes from being expired after commit by default;\n* support different types of request handlers;\n* support nested applications.\n\n\nDocumentation\n-------------\nhttps://aiohttp-sqlalchemy.readthedocs.io\n\n\nInstallation\n------------\n::\n\n    pip install aiohttp-sqlalchemy\n\n\nSimple example\n--------------\nInstall ``aiosqlite`` for work with sqlite3: ::\n\n  pip install aiosqlite\n\nCopy and paste this code in a file and run:\n\n.. code-block:: python\n\n  from datetime import datetime\n\n  import sqlalchemy as sa\n  from aiohttp import web\n  from sqlalchemy import orm\n\n  import aiohttp_sqlalchemy as ahsa\n\n\n  class Base(orm.DeclarativeBase): ...\n\n\n  class MyModel(Base):\n      __tablename__ = \"my_table\"\n\n      pk = sa.Column(sa.Integer, primary_key=True)\n      timestamp = sa.Column(sa.DateTime(), default=datetime.now)\n\n\n  async def main(request):\n      sa_session = aiohttp_sqlalchemy.get_session(request)\n\n      async with sa_session.begin():\n          sa_session.add(MyModel())\n          result = await sa_session.execute(sa.select(MyModel))\n          result = result.scalars()\n\n      data = {instance.pk: instance.timestamp.isoformat() for instance in result}\n      return web.json_response(data)\n\n\n  async def app_factory():\n      app = web.Application()\n\n      aiohttp_sqlalchemy.setup(\n          app,\n          [\n              aiohttp_sqlalchemy.bind(\"sqlite+aiosqlite:///\"),\n          ],\n      )\n      await aiohttp_sqlalchemy.init_db(app, Base.metadata)\n\n      app.add_routes([web.get(\"/\", main)])\n      return app\n\n\n  if __name__ == \"__main__\":\n      web.run_app(app_factory(), port=8087)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "SQLAlchemy 2.0 support for aiohttp.",
    "version": "1.1.0",
    "project_urls": {
        "Documentation": "https://aiohttp-sqlalchemy.readthedocs.io/",
        "Homepage": "https://pypi.org/project/aiohttp-sqlalchemy/",
        "Repository": "https://github.com/ri-gilfanov/aiohttp-sqlalchemy"
    },
    "split_keywords": [
        "aiohttp",
        " sqlalchemy",
        " asyncio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8212592e834e28f4ddafe194accf328592917542af79405a982ba7247c527ce",
                "md5": "d440b7c00f78adb842aee7112009aa91",
                "sha256": "78059cab100fbf6ddfe35f616d85212061fb80769d3dc96cda0130c6934ef1ea"
            },
            "downloads": -1,
            "filename": "aiohttp_sqlalchemy-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d440b7c00f78adb842aee7112009aa91",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 9800,
            "upload_time": "2024-12-06T04:26:34",
            "upload_time_iso_8601": "2024-12-06T04:26:34.516321Z",
            "url": "https://files.pythonhosted.org/packages/a8/21/2592e834e28f4ddafe194accf328592917542af79405a982ba7247c527ce/aiohttp_sqlalchemy-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4a2c9567c4ff890f7d3bf248727bdd7911c867084b77927568fa3f8b64e4b04f",
                "md5": "6e1890bcad9fca618e6049c0eb944ecc",
                "sha256": "8a3c87e002f6a70270c8b9158ded959e6458239a1ebbe519b9f6c731a5d5530c"
            },
            "downloads": -1,
            "filename": "aiohttp_sqlalchemy-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6e1890bcad9fca618e6049c0eb944ecc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 8631,
            "upload_time": "2024-12-06T04:26:36",
            "upload_time_iso_8601": "2024-12-06T04:26:36.422286Z",
            "url": "https://files.pythonhosted.org/packages/4a/2c/9567c4ff890f7d3bf248727bdd7911c867084b77927568fa3f8b64e4b04f/aiohttp_sqlalchemy-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-06 04:26:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ri-gilfanov",
    "github_project": "aiohttp-sqlalchemy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aiohttp-sqlalchemy"
}
        
Elapsed time: 0.49869s