aiohttp-sqlalchemy


Nameaiohttp-sqlalchemy JSON
Version 1.0.post0 PyPI version JSON
download
home_pagehttps://pypi.org/project/aiohttp-sqlalchemy/
SummarySQLAlchemy 2.0 support for aiohttp.
upload_time2024-09-15 07:08:46
maintainerRuslan Ilyasovich Gilfanov
docs_urlNone
authorRuslan Ilyasovich Gilfanov
requires_python<4.0,>=3.8
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| |PyPI downloads| |Python versions| |License| |GitHub CI| |Codecov| |Codacy|

.. |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.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-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

.. |Codecov| image:: https://codecov.io/gh/ri-gilfanov/aiohttp-sqlalchemy/branch/master/graph/badge.svg
  :target: https://codecov.io/gh/ri-gilfanov/aiohttp-sqlalchemy
  :alt: codecov.io status for master branch

.. |Codacy| image:: https://app.codacy.com/project/badge/Grade/19d5c531ed75435988ba8dc91031514c
  :target: https://www.codacy.com/gh/ri-gilfanov/aiohttp-sqlalchemy/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ri-gilfanov/aiohttp-sqlalchemy&amp;utm_campaign=Badge_Grade
   :alt: Codacy code quality

`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

  metadata = sa.MetaData()
  Base = orm.declarative_base(metadata=metadata)


  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 = ahsa.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()

      ahsa.setup(app, [
          ahsa.bind('sqlite+aiosqlite:///'),
      ])
      await ahsa.init_db(app, metadata)

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


  if __name__ == '__main__':
      web.run_app(app_factory())

            

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.8",
    "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/a7/06/fcc11f54c75fa7f62847fd2068a3e387241fb09d7b04bbfcf703b88bdd55/aiohttp_sqlalchemy-1.0.post0.tar.gz",
    "platform": null,
    "description": "==================\naiohttp-sqlalchemy\n==================\n|ReadTheDocs| |PyPI release| |PyPI downloads| |Python versions| |License| |GitHub CI| |Codecov| |Codacy|\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.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-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.. |Codecov| image:: https://codecov.io/gh/ri-gilfanov/aiohttp-sqlalchemy/branch/master/graph/badge.svg\n  :target: https://codecov.io/gh/ri-gilfanov/aiohttp-sqlalchemy\n  :alt: codecov.io status for master branch\n\n.. |Codacy| image:: https://app.codacy.com/project/badge/Grade/19d5c531ed75435988ba8dc91031514c\n  :target: https://www.codacy.com/gh/ri-gilfanov/aiohttp-sqlalchemy/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ri-gilfanov/aiohttp-sqlalchemy&amp;utm_campaign=Badge_Grade\n   :alt: Codacy code quality\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  metadata = sa.MetaData()\n  Base = orm.declarative_base(metadata=metadata)\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 = ahsa.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 = {\n          instance.pk: instance.timestamp.isoformat()\n          for instance in result\n      }\n      return web.json_response(data)\n\n\n  async def app_factory():\n      app = web.Application()\n\n      ahsa.setup(app, [\n          ahsa.bind('sqlite+aiosqlite:///'),\n      ])\n      await ahsa.init_db(app, metadata)\n\n      app.add_routes([web.get('/', main)])\n      return app\n\n\n  if __name__ == '__main__':\n      web.run_app(app_factory())\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "SQLAlchemy 2.0 support for aiohttp.",
    "version": "1.0.post0",
    "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": "c0d2dbb71c841ef84baad2be5a4039bc99dd42fe30ff27c257209f5a5aef51fc",
                "md5": "081ef4f5746d7ddff9408355befe15ed",
                "sha256": "3fffd32e7bad10d7ee386d4ef47ec9de4dcf3925a19c0dadd3eea633ba64989d"
            },
            "downloads": -1,
            "filename": "aiohttp_sqlalchemy-1.0.post0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "081ef4f5746d7ddff9408355befe15ed",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 10031,
            "upload_time": "2024-09-15T07:08:44",
            "upload_time_iso_8601": "2024-09-15T07:08:44.445896Z",
            "url": "https://files.pythonhosted.org/packages/c0/d2/dbb71c841ef84baad2be5a4039bc99dd42fe30ff27c257209f5a5aef51fc/aiohttp_sqlalchemy-1.0.post0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a706fcc11f54c75fa7f62847fd2068a3e387241fb09d7b04bbfcf703b88bdd55",
                "md5": "9af9b8c5a4a9bb1ad65f797092481975",
                "sha256": "1606e7114492a621d2a7ade4740fd4cd78d0d73937b6368adfc55cd4565de8ab"
            },
            "downloads": -1,
            "filename": "aiohttp_sqlalchemy-1.0.post0.tar.gz",
            "has_sig": false,
            "md5_digest": "9af9b8c5a4a9bb1ad65f797092481975",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 9004,
            "upload_time": "2024-09-15T07:08:46",
            "upload_time_iso_8601": "2024-09-15T07:08:46.392988Z",
            "url": "https://files.pythonhosted.org/packages/a7/06/fcc11f54c75fa7f62847fd2068a3e387241fb09d7b04bbfcf703b88bdd55/aiohttp_sqlalchemy-1.0.post0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-15 07:08:46",
    "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.35460s