Skip to main content

Async support for a range of databases

Project description

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.

Project details


Download files

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

Source Distribution

muffin_databases-0.6.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

muffin_databases-0.6.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file muffin_databases-0.6.1.tar.gz.

File metadata

  • Download URL: muffin_databases-0.6.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1024-azure

File hashes

Hashes for muffin_databases-0.6.1.tar.gz
Algorithm Hash digest
SHA256 dca0e4651300e0b9326d693b4188fab8e3b6b748d1fb59774f128a24bbf21b6a
MD5 2801447c40fbf4197c036ee053340509
BLAKE2b-256 800bb9d1491014a310e40d89e45b357a25c4fc78c96a80b88d8d939fbe4a62b5

See more details on using hashes here.

File details

Details for the file muffin_databases-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: muffin_databases-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1024-azure

File hashes

Hashes for muffin_databases-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 45b104182699823676d7ad63802d72194e6ae8c2635335171673bbd9d78dad61
MD5 da2296da6e963471df97fbc66d9cee78
BLAKE2b-256 dc0030d6bd9805535675491e4d0d8cce7fa079ba73dcd720187d072f051c8c32

See more details on using hashes here.

Supported by

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