muffin-databases


Namemuffin-databases JSON
Version 0.6.2 PyPI version JSON
download
home_pagehttps://github.com/klen/muffin-databases
SummaryAsync support for a range of databases
upload_time2024-11-01 11:08:30
maintainerNone
docs_urlNone
authorKirill Klenov
requires_python<4.0,>=3.9
licenseMIT
keywords sql postgres mysql sqlite asyncio asgi web muffin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Muffin-Databases
################

.. _description:

**Muffin-Databases** -- Async support for a range of databases for Muffin_ Framework

.. _badges:

.. image:: https://github.com/klen/muffin-databases/workflows/tests/badge.svg
    :target: https://github.com/klen/muffin-databases/actions
    :alt: Tests Status

.. image:: https://img.shields.io/pypi/v/muffin-databases
    :target: https://pypi.org/project/muffin-databases/
    :alt: PYPI Version

.. image:: https://img.shields.io/pypi/pyversions/muffin-databases
    :target: https://pypi.org/project/muffin-databases/
    :alt: Python Versions

.. _contents:

.. contents::

.. _requirements:

Requirements
=============

- python >= 3.9

.. note:: The plugin supports only asyncio evenloop (not trio)

.. _installation:

Installation
=============

**Muffin-Databases** should be installed using pip: ::

    $ pip install muffin-databases

Optionally you can install the required database drivers with: ::

    $ pip install muffin-databases[sqlite]
    $ pip install muffin-databases[postgres]
    $ pip install muffin-databases[mysql]

Driver support is provided using one of asyncpg_, aiomysql_, or aiosqlite_.

.. _usage:

Usage
=====

Setup the plugin and connect it into your app:

.. code-block:: python

    from muffin import Application
    from muffin_databases import Plugin as DB

    # Create Muffin Application
    app = Application('example')

    # Initialize the plugin
    # As alternative: db = DB(app, **options)
    db = DB(url='sqlite:///db.sqlite')
    db.setup(app)


That's it now you are able to use the plugin inside your views:

.. code-block:: python

    @app.route('/items', methods=['GET'])
    async def get_items(request):
        """Return a JSON with items from database."""
        rows = await db.fetch_all('SELECT * from items')
        return [dict(row.items()) for row in rows]

    @app.route('/items', methods=['POST'])
    async def insert_item(request):
        """Store an item into database."""
        data = await request.data()  # parse formdata/json from the request
        await db.execute_many('INSERT INTO items (name, value) VALUES (:name, :value)', values=data)
        return 'OK'

The Muffin-Databases plugin is based on databases_. See the databases_'s docs for further references.


Options
-------

=========================== ======================================= ===========================
Name                        Default value                           Desctiption
--------------------------- --------------------------------------- ---------------------------
**url**                     ``"sqlite:///db.sqlite"``               A database connection URL
**params**                  ``{}``                                  A database connection params
=========================== ======================================= ===========================


You are able to provide the options when you are initiliazing the plugin:

.. code-block:: python

    db.setup(app, url='postgresql://localhost/example', params={'ssl': True, 'min_size': 5, 'max_size': 20})

Or setup it from ``Muffin.Application`` configuration using the ``DATABASES_`` prefix:

.. code-block:: python

   DATABASES_URL = 'postgresql://localhost/example'

``Muffin.Application`` configuration options are case insensitive

.. _bugtracker:

Bug tracker
===========

If you have any suggestions, bug reports or
annoyances please report them to the issue tracker
at https://github.com/klen/muffin-databases/issues

.. _contributing:

Contributing
============

Development of Muffin-Databases happens at: https://github.com/klen/muffin-databases


Contributors
=============

* klen_ (Kirill Klenov)

.. _license:

License
========

Licensed under a `MIT license`_.

.. _links:


.. _klen: https://github.com/klen
.. _Muffin: https://github.com/klen/muffin

.. _asyncpg: https://github.com/MagicStack/asyncpg
.. _aiomysql: https://aiomysql.readthedocs.io/en/latest/
.. _aiosqlite: https://github.com/omnilib/aiosqlite
.. _databases: https://www.encode.io/databases/

.. _MIT license: http://opensource.org/licenses/MIT

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/klen/muffin-databases",
    "name": "muffin-databases",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "sql, postgres, mysql, sqlite, asyncio, asgi, web, muffin",
    "author": "Kirill Klenov",
    "author_email": "horneds@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e7/4c/95840d5ec2cc14db62aa8116214f543b7dcd6594d1930bc1995f87540775/muffin_databases-0.6.2.tar.gz",
    "platform": null,
    "description": "Muffin-Databases\n################\n\n.. _description:\n\n**Muffin-Databases** -- Async support for a range of databases for Muffin_ Framework\n\n.. _badges:\n\n.. image:: https://github.com/klen/muffin-databases/workflows/tests/badge.svg\n    :target: https://github.com/klen/muffin-databases/actions\n    :alt: Tests Status\n\n.. image:: https://img.shields.io/pypi/v/muffin-databases\n    :target: https://pypi.org/project/muffin-databases/\n    :alt: PYPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/muffin-databases\n    :target: https://pypi.org/project/muffin-databases/\n    :alt: Python Versions\n\n.. _contents:\n\n.. contents::\n\n.. _requirements:\n\nRequirements\n=============\n\n- python >= 3.9\n\n.. note:: The plugin supports only asyncio evenloop (not trio)\n\n.. _installation:\n\nInstallation\n=============\n\n**Muffin-Databases** should be installed using pip: ::\n\n    $ pip install muffin-databases\n\nOptionally you can install the required database drivers with: ::\n\n    $ pip install muffin-databases[sqlite]\n    $ pip install muffin-databases[postgres]\n    $ pip install muffin-databases[mysql]\n\nDriver support is provided using one of asyncpg_, aiomysql_, or aiosqlite_.\n\n.. _usage:\n\nUsage\n=====\n\nSetup the plugin and connect it into your app:\n\n.. code-block:: python\n\n    from muffin import Application\n    from muffin_databases import Plugin as DB\n\n    # Create Muffin Application\n    app = Application('example')\n\n    # Initialize the plugin\n    # As alternative: db = DB(app, **options)\n    db = DB(url='sqlite:///db.sqlite')\n    db.setup(app)\n\n\nThat's it now you are able to use the plugin inside your views:\n\n.. code-block:: python\n\n    @app.route('/items', methods=['GET'])\n    async def get_items(request):\n        \"\"\"Return a JSON with items from database.\"\"\"\n        rows = await db.fetch_all('SELECT * from items')\n        return [dict(row.items()) for row in rows]\n\n    @app.route('/items', methods=['POST'])\n    async def insert_item(request):\n        \"\"\"Store an item into database.\"\"\"\n        data = await request.data()  # parse formdata/json from the request\n        await db.execute_many('INSERT INTO items (name, value) VALUES (:name, :value)', values=data)\n        return 'OK'\n\nThe Muffin-Databases plugin is based on databases_. See the databases_'s docs for further references.\n\n\nOptions\n-------\n\n=========================== ======================================= ===========================\nName                        Default value                           Desctiption\n--------------------------- --------------------------------------- ---------------------------\n**url**                     ``\"sqlite:///db.sqlite\"``               A database connection URL\n**params**                  ``{}``                                  A database connection params\n=========================== ======================================= ===========================\n\n\nYou are able to provide the options when you are initiliazing the plugin:\n\n.. code-block:: python\n\n    db.setup(app, url='postgresql://localhost/example', params={'ssl': True, 'min_size': 5, 'max_size': 20})\n\nOr setup it from ``Muffin.Application`` configuration using the ``DATABASES_`` prefix:\n\n.. code-block:: python\n\n   DATABASES_URL = 'postgresql://localhost/example'\n\n``Muffin.Application`` configuration options are case insensitive\n\n.. _bugtracker:\n\nBug tracker\n===========\n\nIf you have any suggestions, bug reports or\nannoyances please report them to the issue tracker\nat https://github.com/klen/muffin-databases/issues\n\n.. _contributing:\n\nContributing\n============\n\nDevelopment of Muffin-Databases happens at: https://github.com/klen/muffin-databases\n\n\nContributors\n=============\n\n* klen_ (Kirill Klenov)\n\n.. _license:\n\nLicense\n========\n\nLicensed under a `MIT license`_.\n\n.. _links:\n\n\n.. _klen: https://github.com/klen\n.. _Muffin: https://github.com/klen/muffin\n\n.. _asyncpg: https://github.com/MagicStack/asyncpg\n.. _aiomysql: https://aiomysql.readthedocs.io/en/latest/\n.. _aiosqlite: https://github.com/omnilib/aiosqlite\n.. _databases: https://www.encode.io/databases/\n\n.. _MIT license: http://opensource.org/licenses/MIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Async support for a range of databases",
    "version": "0.6.2",
    "project_urls": {
        "Homepage": "https://github.com/klen/muffin-databases",
        "Repository": "https://github.com/klen/muffin-databases"
    },
    "split_keywords": [
        "sql",
        " postgres",
        " mysql",
        " sqlite",
        " asyncio",
        " asgi",
        " web",
        " muffin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6ff26d47b2e1feec072cf4ebc9788a85e0fda6dc978c91b98f4dfb9f444dca60",
                "md5": "016381e378bdaaea956274cf943abea9",
                "sha256": "183b6668c80dfcfae2c9feb208c99c3762565033b8b544a9c757b20f6592c98f"
            },
            "downloads": -1,
            "filename": "muffin_databases-0.6.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "016381e378bdaaea956274cf943abea9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 4329,
            "upload_time": "2024-11-01T11:08:28",
            "upload_time_iso_8601": "2024-11-01T11:08:28.917476Z",
            "url": "https://files.pythonhosted.org/packages/6f/f2/6d47b2e1feec072cf4ebc9788a85e0fda6dc978c91b98f4dfb9f444dca60/muffin_databases-0.6.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e74c95840d5ec2cc14db62aa8116214f543b7dcd6594d1930bc1995f87540775",
                "md5": "104be5d49d0775cedfd951eb7a89a329",
                "sha256": "a73d742236628a7329ce8f4d5b9715c1a0e988771a04b301f18ce639e77e73b8"
            },
            "downloads": -1,
            "filename": "muffin_databases-0.6.2.tar.gz",
            "has_sig": false,
            "md5_digest": "104be5d49d0775cedfd951eb7a89a329",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 4149,
            "upload_time": "2024-11-01T11:08:30",
            "upload_time_iso_8601": "2024-11-01T11:08:30.597523Z",
            "url": "https://files.pythonhosted.org/packages/e7/4c/95840d5ec2cc14db62aa8116214f543b7dcd6594d1930bc1995f87540775/muffin_databases-0.6.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-01 11:08:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "klen",
    "github_project": "muffin-databases",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "muffin-databases"
}
        
Elapsed time: 0.75791s