muffin-peewee-aio


Namemuffin-peewee-aio JSON
Version 1.4.0 PyPI version JSON
download
home_pagehttps://github.com/klen/muffin-peewee
SummaryPeewee-AIO integration for Muffin framework
upload_time2025-07-15 12:24:10
maintainerNone
docs_urlNone
authorKirill Klenov
requires_python<4.0,>=3.10
licenseMIT
keywords peewee sql orm asyncio muffin
VCS
bugtrack_url
requirements aio-peewee muffin peewee peewee-migrate
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Muffin Peewee AIO
#################

**muffin-peewee-aio** — Asynchronous Peewee_ ORM integration for the Muffin_ framework.

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

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

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

.. contents::

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

- Python >= 3.10

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

Install via pip: ::

    $ pip install muffin-peewee-aio

You can include an async database driver as needed: ::

    $ pip install muffin-peewee-aio[aiosqlite]
    $ pip install muffin-peewee-aio[aiopg]
    $ pip install muffin-peewee-aio[asyncpg]
    $ pip install muffin-peewee-aio[aiomysql]

Usage
=====

.. code-block:: python

    from muffin import Application
    from muffin_peewee import Plugin as Peewee

    # Create the application
    app = Application("example")

    # Initialize the plugin
    db = Peewee()
    db.setup(app, PEEWEE_CONNECTION="postgresql://postgres:postgres@localhost:5432/database")

    # Or: db = Peewee(app, **options)


Configuration
=============

You can provide options either at initialization or through the application config.

+------------------------+-----------------------------------------+----------------------------------------------------+
| Name                   | Default                                 | Description                                        |
+========================+=========================================+====================================================+
| **CONNECTION**         | ``sqlite:///db.sqlite``                 | Database connection URL                            |
+------------------------+-----------------------------------------+----------------------------------------------------+
| **CONNECTION_PARAMS**  | ``{}``                                  | Extra options passed to the database backend       |
+------------------------+-----------------------------------------+----------------------------------------------------+
| **AUTO_CONNECTION**    | ``True``                                | Automatically acquire a DB connection per request  |
+------------------------+-----------------------------------------+----------------------------------------------------+
| **AUTO_TRANSACTION**   | ``True``                                | Automatically wrap each request in a transaction   |
+------------------------+-----------------------------------------+----------------------------------------------------+
| **MIGRATIONS_ENABLED** | ``True``                                | Enable the migration engine                        |
+------------------------+-----------------------------------------+----------------------------------------------------+
| **MIGRATIONS_PATH**    | ``"migrations"``                        | Path to store migration files                      |
+------------------------+-----------------------------------------+----------------------------------------------------+
| **PYTEST_SETUP_DB**    | ``True``                                | Manage DB setup and teardown in pytest             |
+------------------------+-----------------------------------------+----------------------------------------------------+

You can also define options in the `Application` config using the `PEEWEE_` prefix: ::

    PEEWEE_CONNECTION = "postgresql://..."

Note: Muffin application config is case-insensitive.

Models and Queries
==================

Define your model:

.. code-block:: python

    class Test(db.Model):
        data = peewee.CharField()

Query the database:

.. code-block:: python

    @app.route("/")
    async def view(request):
        return [t.data async for t in Test.select()]

Connection Management
=====================

By default, connections and transactions are managed automatically.
To manage them manually, disable the config flags and use context managers:

.. code-block:: python

    @app.route("/")
    async def view(request):
        async with db.connection():
            async with db.transaction():
                # Perform DB operations here
                ...

Migrations
==========

Create a migration: ::

    $ muffin example:app peewee-create [NAME] [--auto]

Run migrations: ::

    $ muffin example:app peewee-migrate [NAME] [--fake]

Rollback the latest migration: ::

    $ muffin example:app peewee-rollback

List all migrations: ::

    $ muffin example:app peewee-list

Clear migration history from the database: ::

    $ muffin example:app peewee-clear

Merge all migrations into one: ::

    $ muffin example:app peewee-merge

Testing Support
===============

You can use the `conftest()` context manager to auto-manage schema setup and teardown during testing:

.. code-block:: python

    import pytest

    @pytest.mark.asyncio
    async def test_example():
        async with db.conftest():
            # Tables are created and dropped automatically
            ...

Bug Tracker
===========

Found a bug or have a suggestion? Please open an issue at:
https://github.com/klen/muffin-peewee-aio/issues

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

Development takes place at: https://github.com/klen/muffin-peewee-aio
Pull requests are welcome!

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

* `klen`_ (Kirill Klenov)

License
=======

This project is licensed under the `MIT license`_.

.. _links:

.. _MIT license: http://opensource.org/licenses/MIT
.. _Muffin: https://github.com/klen/muffin
.. _Peewee: http://docs.peewee-orm.com/en/latest/
.. _klen: https://github.com/klen

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/klen/muffin-peewee",
    "name": "muffin-peewee-aio",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "peewee, sql, orm, asyncio, muffin",
    "author": "Kirill Klenov",
    "author_email": "horneds@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9a/e1/ecf174474953d76eeff9658419a72d6381989bc132aaa53789b8d9afcad9/muffin_peewee_aio-1.4.0.tar.gz",
    "platform": null,
    "description": "Muffin Peewee AIO\n#################\n\n**muffin-peewee-aio** \u2014 Asynchronous Peewee_ ORM integration for the Muffin_ framework.\n\n.. image:: https://github.com/klen/muffin-peewee-aio/workflows/tests/badge.svg\n    :target: https://github.com/klen/muffin-peewee-aio/actions\n    :alt: Tests Status\n\n.. image:: https://img.shields.io/pypi/v/muffin-peewee-aio\n    :target: https://pypi.org/project/muffin-peewee-aio/\n    :alt: PYPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/muffin-peewee-aio\n    :target: https://pypi.org/project/muffin-peewee-aio/\n    :alt: Python Versions\n\n.. contents::\n\nRequirements\n============\n\n- Python >= 3.10\n\nInstallation\n============\n\nInstall via pip: ::\n\n    $ pip install muffin-peewee-aio\n\nYou can include an async database driver as needed: ::\n\n    $ pip install muffin-peewee-aio[aiosqlite]\n    $ pip install muffin-peewee-aio[aiopg]\n    $ pip install muffin-peewee-aio[asyncpg]\n    $ pip install muffin-peewee-aio[aiomysql]\n\nUsage\n=====\n\n.. code-block:: python\n\n    from muffin import Application\n    from muffin_peewee import Plugin as Peewee\n\n    # Create the application\n    app = Application(\"example\")\n\n    # Initialize the plugin\n    db = Peewee()\n    db.setup(app, PEEWEE_CONNECTION=\"postgresql://postgres:postgres@localhost:5432/database\")\n\n    # Or: db = Peewee(app, **options)\n\n\nConfiguration\n=============\n\nYou can provide options either at initialization or through the application config.\n\n+------------------------+-----------------------------------------+----------------------------------------------------+\n| Name                   | Default                                 | Description                                        |\n+========================+=========================================+====================================================+\n| **CONNECTION**         | ``sqlite:///db.sqlite``                 | Database connection URL                            |\n+------------------------+-----------------------------------------+----------------------------------------------------+\n| **CONNECTION_PARAMS**  | ``{}``                                  | Extra options passed to the database backend       |\n+------------------------+-----------------------------------------+----------------------------------------------------+\n| **AUTO_CONNECTION**    | ``True``                                | Automatically acquire a DB connection per request  |\n+------------------------+-----------------------------------------+----------------------------------------------------+\n| **AUTO_TRANSACTION**   | ``True``                                | Automatically wrap each request in a transaction   |\n+------------------------+-----------------------------------------+----------------------------------------------------+\n| **MIGRATIONS_ENABLED** | ``True``                                | Enable the migration engine                        |\n+------------------------+-----------------------------------------+----------------------------------------------------+\n| **MIGRATIONS_PATH**    | ``\"migrations\"``                        | Path to store migration files                      |\n+------------------------+-----------------------------------------+----------------------------------------------------+\n| **PYTEST_SETUP_DB**    | ``True``                                | Manage DB setup and teardown in pytest             |\n+------------------------+-----------------------------------------+----------------------------------------------------+\n\nYou can also define options in the `Application` config using the `PEEWEE_` prefix: ::\n\n    PEEWEE_CONNECTION = \"postgresql://...\"\n\nNote: Muffin application config is case-insensitive.\n\nModels and Queries\n==================\n\nDefine your model:\n\n.. code-block:: python\n\n    class Test(db.Model):\n        data = peewee.CharField()\n\nQuery the database:\n\n.. code-block:: python\n\n    @app.route(\"/\")\n    async def view(request):\n        return [t.data async for t in Test.select()]\n\nConnection Management\n=====================\n\nBy default, connections and transactions are managed automatically.\nTo manage them manually, disable the config flags and use context managers:\n\n.. code-block:: python\n\n    @app.route(\"/\")\n    async def view(request):\n        async with db.connection():\n            async with db.transaction():\n                # Perform DB operations here\n                ...\n\nMigrations\n==========\n\nCreate a migration: ::\n\n    $ muffin example:app peewee-create [NAME] [--auto]\n\nRun migrations: ::\n\n    $ muffin example:app peewee-migrate [NAME] [--fake]\n\nRollback the latest migration: ::\n\n    $ muffin example:app peewee-rollback\n\nList all migrations: ::\n\n    $ muffin example:app peewee-list\n\nClear migration history from the database: ::\n\n    $ muffin example:app peewee-clear\n\nMerge all migrations into one: ::\n\n    $ muffin example:app peewee-merge\n\nTesting Support\n===============\n\nYou can use the `conftest()` context manager to auto-manage schema setup and teardown during testing:\n\n.. code-block:: python\n\n    import pytest\n\n    @pytest.mark.asyncio\n    async def test_example():\n        async with db.conftest():\n            # Tables are created and dropped automatically\n            ...\n\nBug Tracker\n===========\n\nFound a bug or have a suggestion? Please open an issue at:\nhttps://github.com/klen/muffin-peewee-aio/issues\n\nContributing\n============\n\nDevelopment takes place at: https://github.com/klen/muffin-peewee-aio\nPull requests are welcome!\n\nContributors\n============\n\n* `klen`_ (Kirill Klenov)\n\nLicense\n=======\n\nThis project is licensed under the `MIT license`_.\n\n.. _links:\n\n.. _MIT license: http://opensource.org/licenses/MIT\n.. _Muffin: https://github.com/klen/muffin\n.. _Peewee: http://docs.peewee-orm.com/en/latest/\n.. _klen: https://github.com/klen\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Peewee-AIO integration for Muffin framework",
    "version": "1.4.0",
    "project_urls": {
        "Homepage": "https://github.com/klen/muffin-peewee",
        "Repository": "https://github.com/klen/muffin-peewee"
    },
    "split_keywords": [
        "peewee",
        " sql",
        " orm",
        " asyncio",
        " muffin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6ba334b80df05ed82caefd80f809f07fb112c82180610959620153726aec162",
                "md5": "ea11be6d69f1e10144395104f3f95f57",
                "sha256": "f3f803333c841b3ee8575e76b690ab3c17bb45f4ac97ae5351cd546d4909a84f"
            },
            "downloads": -1,
            "filename": "muffin_peewee_aio-1.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ea11be6d69f1e10144395104f3f95f57",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 7335,
            "upload_time": "2025-07-15T12:24:09",
            "upload_time_iso_8601": "2025-07-15T12:24:09.819525Z",
            "url": "https://files.pythonhosted.org/packages/a6/ba/334b80df05ed82caefd80f809f07fb112c82180610959620153726aec162/muffin_peewee_aio-1.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9ae1ecf174474953d76eeff9658419a72d6381989bc132aaa53789b8d9afcad9",
                "md5": "d0b830ebefd23fed7c3b1963d555389d",
                "sha256": "a77944142c5d34b22e7bfc39060517b5cf39458cc39659dd25e0a980883f277a"
            },
            "downloads": -1,
            "filename": "muffin_peewee_aio-1.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d0b830ebefd23fed7c3b1963d555389d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 6702,
            "upload_time": "2025-07-15T12:24:10",
            "upload_time_iso_8601": "2025-07-15T12:24:10.698125Z",
            "url": "https://files.pythonhosted.org/packages/9a/e1/ecf174474953d76eeff9658419a72d6381989bc132aaa53789b8d9afcad9/muffin_peewee_aio-1.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-15 12:24:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "klen",
    "github_project": "muffin-peewee",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "aio-peewee",
            "specs": [
                [
                    ">=",
                    "0.4.0"
                ]
            ]
        },
        {
            "name": "muffin",
            "specs": [
                [
                    ">=",
                    "0.83"
                ]
            ]
        },
        {
            "name": "peewee",
            "specs": [
                [
                    ">=",
                    "3"
                ]
            ]
        },
        {
            "name": "peewee-migrate",
            "specs": [
                [
                    ">=",
                    "1.6.2"
                ]
            ]
        }
    ],
    "lcname": "muffin-peewee-aio"
}
        
Elapsed time: 0.44875s