A serverless Mongo-like database backed with SQLite.
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
pyyaml
jsonschema
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}
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.
>>> client = MontyClient(":memory:")
- SQLite
SQLite is the default on-disk storage engine, you can skip the configuration if the default setting is okay.
>>> client = MontyClient("/db/repo")
SQLite default settings, they are infact SQLite pragmas:
connection:
journal_mode: WAL
write_concern:
synchronous: 1
automatic_index: OFF
busy_timeout: 5000
If you are not happy with the default, use MontyConfigure
before get client.
>>> from montydb import MontyClient, MontyConfigure, storage
>>> with MontyConfigure("/db/repo") as cf: # Auto save config when exit
... cf.load(storage.SQLiteConfig) # Load sqlite config
... cf.config.connection.journal_mode = "DELETE"
... cf.config.write_concern.busy_timeout = 8000
...
>>> client = MontyClient("/db/repo") # Running tweaked sqlite storage now
- FlatFile
Not default storage engine, need configuration first before get client.
>>> from montydb import MontyClient, MontyConfigure, storage
>>> with MontyConfigure("/db/repo") as cf: # Auto save config when exit
... cf.load(storage.FlatFileConfig) # Load flatfile config
...
>>> client = MontyClient("/db/repo") # Running on flatfile storage now
FlatFile default settings:
connection:
cache_modified: 0 # how many document CRUD cached before flush to disk.
Change storage engine
MontyConfigure
will ignore load()
if conf.yaml
exists, you need to drop()
first before changing the storage engine. The documents will remain on disk and conf.yaml
will be deleted.
>>> with MontyConfigure("/db/repo") as cf:
... cf.drop()
... cf.load(storage.WhateverConfig)
Reload configuration
MontyClient
will reload conf.yaml
at the operation right after client.close()
.
>>> client.close()
>>> col.insert_one({"doc": 1}) # client auto re-open and reload config
After storage engine configuration, you should feel like using MongoDB's Python driver, unless it's not implemented.
Develop Status
See Projects' TODO
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.
Source Distribution
Built Distribution
File details
Details for the file montydb-0.0.3.tar.gz
.
File metadata
- Download URL: montydb-0.0.3.tar.gz
- Upload date:
- Size: 34.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e01375d8ce2fc9b3cf751091e6487453f4294dd991f220b8020d63420d5e1fd |
|
MD5 | 1a4d39c67f630f81f4c9598d1d1a1f6b |
|
BLAKE2b-256 | c3324cfa7550c180e76c27bd036add514acbf58d5600b5d88fcbba290d616491 |
Provenance
File details
Details for the file montydb-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: montydb-0.0.3-py3-none-any.whl
- Upload date:
- Size: 43.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c184a5d5fda4d174b6baaedf410a3784e0b7b29b6f144bf666f9407d017587d |
|
MD5 | c49d161fb76464195d7b12fd89138f4d |
|
BLAKE2b-256 | b84deaea2cc10a079d9be938b87e15ae6ffe01c0d589e1b2160dfc8ddf085d63 |