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.9

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

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

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.6.2

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.6.2
File Size Uploaded
muffin_databases-0.6.2.tar.gz 4.1 kB Details

Built distribution (wheel)

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

Total release size: 8.5 kB

Release files / muffin_databases-0.6.2.tar.gz

Download URL muffin_databases-0.6.2.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a73d742236628a7329ce8f4d5b9715c1a0e988771a04b301f18ce639e77e73b8
BLAKE2b-256 checksum
How to use checksums
e74c95840d5ec2cc14db62aa8116214f543b7dcd6594d1930bc1995f87540775
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.10.12 Linux/6.5.0-1025-azure

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

Download URL muffin_databases-0.6.2-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
183b6668c80dfcfae2c9feb208c99c3762565033b8b544a9c757b20f6592c98f
BLAKE2b-256 checksum
How to use checksums
6ff26d47b2e1feec072cf4ebc9788a85e0fda6dc978c91b98f4dfb9f444dca60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.10.12 Linux/6.5.0-1025-azure

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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