MongoDB's unofficial Python implementation.
Project description
Monty, Mongo tinified. A literally serverless, Mongo-like database in Python
: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
(forbson
)
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
ormongoimport
>>> 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
ormongoexport
>>> 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 frommonty_load
>>> monty_dump("/path/dump.json", mtl) >>> MontyList(monty_load("/path/dump.json")) MontyList([1, 2, {'a': 1}, {'a': 5}, {'a': 8}])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.