Skip to main content

MongoDB support for Muffin framework.

Project description

Muffin-Mongo – MongoDB support for Muffin framework.

Tests Status PYPI Version Python Versions

Requirements

  • python >= 3.7

Installation

Muffin-Mongo should be installed using pip:

pip install muffin-mongo

Usage

Setup the plugin and connect it into your app:

from muffin import Application
from muffin_mongo import Plugin as Mongo

# Create Muffin Application
app = Application('example')

# Initialize the plugin
# As alternative: db = DB(app, **options)
mongo = Mongo(db_url='mongodb://localhost:27017', database='db_name')
mongo.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 the database."""
    documents = await mongo.items.find().sort('key').to_list(100)
    return [dict(dd.items(), _id=str(dd['_id'])) for dd in documents]

@app.route('/items', methods=['POST'])
async def insert_item(request):
    """Store items from JSON into database. Return ids."""
    data = await request.data()  # parse formdata/json from the request
    res = await mongo.items.insert_many(data)
    return [str(key) for key in res.inserted_ids]

Configuration options

Name

Default value

Desctiption

db_url

"mongodb://localhost:27017"

A mongo connection URL

database

None

A database name (optional)

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

mongo.setup(app, db_url='mongodb://localhost:27017')

Or setup it from Muffin.Application configuration using the MONGO_ prefix:

MONGO_DB_URL = 'mongodb://localhost:27017'

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-mongo/issues

Contributing

Development of Muffin-Mongo happens at: https://github.com/klen/muffin-mongo

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-mongo-0.4.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

muffin_mongo-0.4.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: muffin-mongo-0.4.0.tar.gz
  • Upload date:
  • Size: 4.5 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-mongo-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8598ef4db6811f96517521147a709a897b352a7c41c3d52b49e4ed3ad0777873
MD5 c3c4437c4ca8c574b94f26b53ce194c2
BLAKE2b-256 216d99b8c0f06c39c21270d3e3924789e6b72f3a9bb2a39f15870bad7732a64d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: muffin_mongo-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 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_mongo-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6abc29e1083158410e429cc8b97488847380262bfada80c81d93a796459b6bf4
MD5 d3cf3e3ed76ac7fb185abd40105fae43
BLAKE2b-256 89c67d51228c6ec6aea778f98d392759b64c30e5f22baddaeeaba6ea49fc1301

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