Skip to main content
MongoCapsule
============

|Build Status|

|Code Climate|

|Test Coverage|

|PyPI|

|PyPI|

Overview
--------

MongoCapsule is a very thin wrapper around MongoEngine built for your
happiness. It encapsulates MongoEngine attributes under a single
namespace and hence allows explicit declaration without context
switches.

In addition to that, MongoCapsule adds pagination support to all the
query results.

MongoEngine is a great ORM for using MongoDB in any Python project.
However, since MongoEngine works in “contexts”, using multiple databases
requires trickery such as ``db_alias`` and ``switch_db``. MongoCapsule
solves this by attaching references to MongoEngine attributes to itself.

Quickstart
----------

If you are familiar with MongoEngine, you can use MongoCapsule already!
Create the database object and use it to define your document and
fields.

.. code:: python

from mongocapsule import MongoCapsule

db = MongoCapsule('test_db')

class Fruits(db.Document):
name = db.StringField()

Refer to `MongoEngine Docs`_ for details.

Installation
------------

To install use pip:

.. code:: bash

pip install mongocapsule

Or clone the repo:

.. code:: bash

git clone https://github.com/prashnts/mongocapsule.git
python setup.py install

Additional API
--------------

MongoCapsule adds Pagination support to the MongoEngine ``QuerySet``
object. It returns 10 objects per page, however, this can be changed.

.. code:: python


# Obtain nth Page of any arbitrary query:

query_results = Document.objects(...).sort(...)

result_page = query_results.page(2) # Obtain second page

total_pages = query_results.page_count

# Update number of items returned per page:

db.QuerySet.set_page_limit(20)

Contributing
------------

Code Patches, suggestions and bug reports welcome! Please use GitHub
issues for the same.

Rant
----

I wrote this module because the examples in official MongoEngine
documentation encourages using ``from mongoengine import *`` which not
only pollutes the local namespace, but makes class definitions implicit.
Of course, cherrypicked imports are possible, however that requires a
lot of extra imports in each files.

The biggest problem, however, comes when you’re using multiple databases
or hosts – in those cases, you need to use context switches or ugly
``meta`` attributes in the declaration.

.. _MongoEngine Docs: http://docs.mongoengine.org/index.html

.. |Build Status| image:: https://img.shields.io/travis/prashnts/mongocapsule/master.svg
:target: https://travis-ci.org/prashnts/mongocapsule
.. |Code Climate| image:: https://img.shields.io/codeclimate/github/prashnts/mongocapsule.svg
:target: https://codeclimate.com/github/prashnts/mongocapsule
.. |Test Coverage| image:: https://img.shields.io/codeclimate/coverage/github/prashnts/mongocapsule.svg
:target: https://codeclimate.com/github/prashnts/mongocapsule
.. |PyPI| image:: https://img.shields.io/pypi/pyversions/mongocapsule.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/mongocapsule
.. |PyPI| image:: https://img.shields.io/pypi/v/mongocapsule.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/mongocapsule

Metadata

Release files for mongocapsule 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongocapsule 0.1.2
File Size Uploaded Provenance
mongocapsule-0.1.2.tar.gz 4.3 kB Without provenance Details

Release files / mongocapsule-0.1.2.tar.gz

Download URL mongocapsule-0.1.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
abed0c565c17b0fd5e2d19a577084eb08d42eaa0b34f500e2404bf4c8e2f52be
BLAKE2b-256 checksum
How to use checksums
b21bf00c6ecfe7966a43dfb63b3066dd831ee81c1d7fd99216a68bf1cd9e4dd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for mongocapsule 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file No provenance

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