Skip to main content

Muffin-Mongo – MongoDB support for Muffin framework.

Tests Status PYPI Version Python Versions

Requirements

  • python >= 3.9

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.

Metadata

Release files for muffin-mongo 0.6.1

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-mongo 0.6.1
File Size Uploaded
muffin_mongo-0.6.1.tar.gz 3.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for muffin-mongo 0.6.1
File Interpreter ABI Platform
muffin_mongo-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 kB

Release files / muffin_mongo-0.6.1.tar.gz

Download URL muffin_mongo-0.6.1.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8b97036c0b04e2249290a6a17373e259aff84b0ac7c380e452690c9d857bd95e
BLAKE2b-256 checksum
How to use checksums
b8df6fabf3155f77a880c535d7285de01ab3ce34536f0a3d617e43890d256d53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1024-azure

Release files / muffin_mongo-0.6.1-py3-none-any.whl

Download URL muffin_mongo-0.6.1-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4ea2ec469e7ae317a2d7d9aeb3d1f9aca03212ea69997645e2a7eb794e4c677
BLAKE2b-256 checksum
How to use checksums
fa9145c7a8faffe410fba23e2b8a650455a321568b6eb5c80df41d921ea61cae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1024-azure

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.5.1

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.5

2 release files

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.1.0

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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