muffin-databases


Namemuffin-databases JSON
Version 0.2.6 PyPI version JSON
download
home_pagehttps://github.com/klen/muffin-databases
SummaryAsync support for a range of databases
upload_time2021-05-11 12:09:36
maintainer
docs_urlNone
authorKirill Klenov
requires_python>=3.7
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

.. _contents:

.. contents::

.. _requirements:

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

- python >= 3.7

.. 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": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "sql,postgres,mysql,sqlite,asyncio,asgi,web,muffin",
    "author": "Kirill Klenov",
    "author_email": "horneds@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0d/25/ca51c881a23f891f5725d3db8a18a8f7f6f9a03bd51a977ae9d660824cf7/muffin-databases-0.2.6.tar.gz",
    "platform": "",
    "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.. _contents:\n\n.. contents::\n\n.. _requirements:\n\nRequirements\n=============\n\n- python >= 3.7\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\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Async support for a range of databases",
    "version": "0.2.6",
    "split_keywords": [
        "sql",
        "postgres",
        "mysql",
        "sqlite",
        "asyncio",
        "asgi",
        "web",
        "muffin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "d499f708c15f2f5e6f4ead6f2081003f",
                "sha256": "d5dcf5f78e111453efe284c27a0e12249565db9afc465529a96237a5cde227c4"
            },
            "downloads": -1,
            "filename": "muffin_databases-0.2.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d499f708c15f2f5e6f4ead6f2081003f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4566,
            "upload_time": "2021-05-11T12:09:35",
            "upload_time_iso_8601": "2021-05-11T12:09:35.733524Z",
            "url": "https://files.pythonhosted.org/packages/7f/b9/8b6417ddb5ec6d58deb16a192257d835817bf04f5bb7dae393b63ba76417/muffin_databases-0.2.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "7355e446105aa6655a91e685bcac0914",
                "sha256": "0de9f3d5745cab6e7f5456d51d75e0f13ec0c5921b1dd215abd9cf10d74d05ff"
            },
            "downloads": -1,
            "filename": "muffin-databases-0.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "7355e446105aa6655a91e685bcac0914",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4854,
            "upload_time": "2021-05-11T12:09:36",
            "upload_time_iso_8601": "2021-05-11T12:09:36.883468Z",
            "url": "https://files.pythonhosted.org/packages/0d/25/ca51c881a23f891f5725d3db8a18a8f7f6f9a03bd51a977ae9d660824cf7/muffin-databases-0.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-05-11 12:09:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "klen",
    "error": "Could not fetch GitHub repository",
    "lcname": "muffin-databases"
}
        
Elapsed time: 0.26718s