Skip to main content

Muffin-Databases

Muffin-Databases – Async support for a range of databases for Muffin Framework

Tests Status PYPI Version Python Versions

Requirements

  • python >= 3.11

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

Setup the plugin and connect it into your app:

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:

@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) 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.

Public API

db.database – the underlying databases.Database instance. Raises RuntimeError if the plugin is not initialized.

Any unknown attribute is proxied to db.database, so the whole databases API is available directly on the plugin: await db.fetch_all(...), await db.fetch_one(...), db.transaction(), await db.execute_many(...) and so on.

The plugin manages the connection for you: on application startup it calls database.connect(), on shutdown it calls database.disconnect().

Options

Name

Default value

Description

url

"sqlite:///:memory:"

A database connection URL

params

{}

A database connection params

Unknown options are ignored.

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

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:

DATABASES_URL = 'postgresql://localhost/example'

Muffin.Application configuration options are case insensitive

Environment variables use the {APP_NAME}_DATABASES_ prefix (the default application name is muffin):

$ export MUFFIN_DATABASES_URL='postgresql://localhost/example'

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

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

Contributors

  • klen (Kirill Klenov)

License

Licensed under a MIT license.

Metadata

Release files for muffin-databases 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for muffin-databases 0.7.0
File Size Uploaded Provenance Actions
muffin_databases-0.7.0.tar.gz 4.3 kB Without provenance Details for muffin_databases-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for muffin-databases 0.7.0
File Interpreter ABI Platform Actions
muffin_databases-0.7.0-py3-none-any.whl Python 3 none any Details for muffin_databases-0.7.0-py3-none-any.whl

Total release size: 8.5 kB

Release files / muffin_databases-0.7.0.tar.gz

Download URL muffin_databases-0.7.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4a510b5340fa35303878f57a60642c284283f9f8e28fd0ab9a62532121104851
BLAKE2b-256 checksum
How to use checksums
942186a4e281e17cbd1f1e0df953062502f8c2f7777c284414c3fe8d5858121e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / muffin_databases-0.7.0-py3-none-any.whl

Download URL muffin_databases-0.7.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
abe49ac3c3e3a4efe81c9d8a73ce8c12e60d899ac0893f4d65bdc82d87ea3285
BLAKE2b-256 checksum
How to use checksums
7cc4223f11b3702d2ecb49d2f4fbff16c9a862543b31fc400c0bd8b2fcd599aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for muffin-databases 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page