Skip to main content

Peewee-AIO integration for Muffin framework

Project description

muffin-peewee-aio — Asynchronous Peewee ORM integration for the Muffin framework.

Tests Status PYPI Version Python Versions

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

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:

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

Query the database:

@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:

@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:

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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

muffin_peewee_aio-2.4.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

muffin_peewee_aio-2.4.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file muffin_peewee_aio-2.4.2.tar.gz.

File metadata

  • Download URL: muffin_peewee_aio-2.4.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for muffin_peewee_aio-2.4.2.tar.gz
Algorithm Hash digest
SHA256 747d6be163a8af0f65f0132a5aed688b17a3d9d692393637bafd57eee1f41976
MD5 1c050c87d4466b08ea64d8f8dec15c70
BLAKE2b-256 e55be48fc3ea0a849dc102404b7a8251d12e73159c91f73d55de34d2ccce30fc

See more details on using hashes here.

File details

Details for the file muffin_peewee_aio-2.4.2-py3-none-any.whl.

File metadata

  • Download URL: muffin_peewee_aio-2.4.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for muffin_peewee_aio-2.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 39fcdc9c28ed53041e1d351ba6f04ec41e369b36ec8e3a369ece0bdd6eb6ba2b
MD5 79365dc4b4b0cdd6171d1277c05affae
BLAKE2b-256 5aa1a3f9a3684b69c48df8f795503dbb2cf629c51799e5dd221c932b15f45162

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page