Skip to main content

An improved package that provides mongodb connectivity. Not compatible with pyramid_mongo or pyramid_mongodb

Project description

Pyramid Mongodb

A simple library to integrate mongodb into your pyramid application. Integrates with pyramid_mongodb2_debugtoolbar.

Features

  • Supports multiple databases
  • Configuration only setup
  • Integrated debugtoolbar
  • Avoids recreating and closing MongoClient on every request.

Setup

pip install pyramid_mongodb2

Add the following to your application's ini file, (include pyramid_mongodb2_debugtoolbar if you want to debug):

[app:main]
mongo_uri = mongodb://username:password@mongodb.host.com:27017/authdb
mongo_dbs = 
    foo
    bar
    baz-quux
pyramid.includes =
    pyramid_mako    
    pyramid_debugtoolbar
    pyramid_mongodb2
    pyramid_mongodb2_debugtoolbar
debugtoolbar.includes =
    pyramid_mongodb2_debugtoolbar:MongoToolbar

The code will use config.add_request_method() to add a Database object to your requests, where each database is accessible by db_database_name, as defined in your configuration.

Note: database names with hyphens in them will be converted to underscores, that is database baz-quux will be accessible by request.db_baz_quux.

In your code where you can access request, you now have the following variables:

request.db
request.db_foo
request.db_bar
request.db_baz_quux

request.db is the MongoClient object, should you ever need it.

In your view code, you can do this:

from pyramid.view import view_config

@view_config(route_name='home', renderer="templates/landing.mako")
def my_view(request):
    return {
        'some_data': request.db_foo.some_collection.find({'a': {'$gte': 5}}, {'_id': False}),
        'other_data': request.db_bar.visitors.insert_one({'person': request.remote_addr}),
    }

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

pyramid_mongodb2-1.5.4.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file pyramid_mongodb2-1.5.4.tar.gz.

File metadata

  • Download URL: pyramid_mongodb2-1.5.4.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.19.4 CPython/3.6.3

File hashes

Hashes for pyramid_mongodb2-1.5.4.tar.gz
Algorithm Hash digest
SHA256 093e3fd1c6ec3bc3d31bcfe16e82d1949b6a08fb86282ad2cc5f9c4080eda9c2
MD5 15823484429acd5b12e2aed9ddd658f4
BLAKE2b-256 c303f88b88385cca1002e442393df38e0de6d5fb6c72f438d9abf2e773184a7c

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