Skip to main content

MongoDB's unofficial Python implementation.

Project description

drawing

Monty, Mongo tinified. A literally serverless, Mongo-like database in Python

Build Status Coverage Status Version Maintainability

:construction: Not Ready For Prime Time :construction:

Inspired by TinyDB and the extension TinyMongo.

MontyDB is:

  • A serverless version of MongoDB, against to MongoDB 3.6.4
  • Document oriented, of course
  • Storage engine pluggable
  • Write in pure Python, works on Python 2.7, 3.4, 3.5, 3.6

Install

pip install montydb

Requirements
  • pymongo (for bson)

Example Code

>>> from montydb import MontyClient
>>> col = MontyClient(":memory:").db.test
>>> col.insert_many([{"stock": "A", "qty": 6}, {"stock": "A", "qty": 2}])

>>> cur = col.find({"stock": "A", "qty": {"$gt": 4}})
>>> next(cur)
{'_id': ObjectId('5ad34e537e8dd45d9c61a456'), 'stock': 'A', 'qty': 6}

Develop Status

See Projects' TODO

Storage Engine Configurations

The configuration process only required on repository creation or modification.

Currently, one repository can only assign one storage engine.

  • Memory

Memory storage does not need nor have any configuration, nothing saved to disk.

>>> from montydb import MontyClient
>>> client = MontyClient(":memory:")
  • FlatFile

FlatFile is the default on-disk storage engine.

>>> from montydb import MontyClient
>>> client = MontyClient("/db/repo")

FlatFile config:

[flatfile]
cache_modified: 0  # how many document CRUD cached before flush to disk.
  • SQLite

SQLite is NOT the default on-disk storage, need configuration first before get client.

>>> from montydb import set_storage, MontyClient
>>> set_storage("/db/repo", storage="sqlite")
>>> client = MontyClient("/db/repo")

SQLite config:

[sqlite]
journal_mode: WAL

SQLite write concern:

>>> client = MontyClient("/db/repo",
>>>                      synchronous=1,
>>>                      automatic_index=False,
>>>                      busy_timeout=5000)

Utilities

  • monty_dump

    Write documents to disk, able to load by monty_load or mongoimport

    >>> from montydb.utils import monty_dump
    >>> documents = [{"a": 1}, {"doc": "some doc"}]
    >>> monty_dump("/path/dump.json", documents)
    
  • monty_load

    Read documents from disk, able to read from monty_dump or mongoexport

    >>> from montydb.utils import monty_load
    >>> monty_load("/path/dump.json")
    [{"a": 1}, {"doc": "some doc"}]
    
  • MontyList

    Experimental, a subclass of list, combined the common CRUD methods from Mongo's Collection and Cursor.

    >>> from montydb.utils import MontyList
    >>> mtl = MontyList([1, 2, {"a": 1}, {"a": 5}, {"a": 8}])
    >>> mtl.find({"a": {"$gt": 3}})
    MontyList([{'a': 5}, {'a': 8}])
    

    You can dump it with monty_dump or read from monty_load

    >>> monty_dump("/path/dump.json", mtl)
    >>> MontyList(monty_load("/path/dump.json"))
    MontyList([1, 2, {'a': 1}, {'a': 5}, {'a': 8}])
    

drawing

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

montydb-1.0.2.tar.gz (42.5 kB view details)

Uploaded Source

Built Distribution

montydb-1.0.2-py3-none-any.whl (53.4 kB view details)

Uploaded Python 3

File details

Details for the file montydb-1.0.2.tar.gz.

File metadata

  • Download URL: montydb-1.0.2.tar.gz
  • Upload date:
  • Size: 42.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.4rc1

File hashes

Hashes for montydb-1.0.2.tar.gz
Algorithm Hash digest
SHA256 531b9b39977959d27579b09c9f5a835322c282f918dd5f2581b76aa05ec5f5d1
MD5 3dd4370979f237da8f6376be54d0adb7
BLAKE2b-256 322282a5079f7bbb1b8890a370e4d70282c0b7ff669218cce81dcef3cdbdbc07

See more details on using hashes here.

Provenance

File details

Details for the file montydb-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: montydb-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 53.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.4rc1

File hashes

Hashes for montydb-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f041f062d235c2b7d24704ea4624c8fe8234468db904d88312fb63f77fe85e42
MD5 585c40440805de6f5a56d430e7dd3ea0
BLAKE2b-256 5d0ec05abf42dcbeee593f7e513c56b150200f5af74fbf3873b8acf865763707

See more details on using hashes here.

Provenance

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