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

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.4.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

muffin_databases-0.4.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file muffin-databases-0.4.0.tar.gz.

File metadata

  • Download URL: muffin-databases-0.4.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for muffin-databases-0.4.0.tar.gz
Algorithm Hash digest
SHA256 15b1c44c324899f6bc99c0249508f9b6472804b6dd416d01a2f0a0a6736b3b6f
MD5 00747b0f12191628a355a3b784e96b18
BLAKE2b-256 d09b07ceaa608a195273a566abe44402cda09187a3200fbe30093e3bb4e5029f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: muffin_databases-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for muffin_databases-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69ee706ee94fc45f5fb283473ac843b15bbb06f83e210e605fcbb6742838ab51
MD5 cd7a8f69ef7f7447f593773d58ea2833
BLAKE2b-256 e5fa28ef9393d42ced5d0f798ea32c0125e7e0260a07999fa0e9c3f89c8a4e32

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