### Install Development Dependencies with uv Source: https://github.com/davidlatwe/montydb/blob/master/README.md Set up the development environment by installing dependencies using 'uv sync'. This command creates a virtual environment and installs all necessary packages for development. ```bash uv sync ``` -------------------------------- ### Install MontyDB Source: https://github.com/davidlatwe/montydb/blob/master/README.md Installs MontyDB using pip or uv. ```sh pip install montydb ``` ```sh uv pip install montydb ``` -------------------------------- ### Example MontyDB Test Execution Source: https://github.com/davidlatwe/montydb/blob/master/README.md An example command to run MontyDB tests against an in-memory storage engine and a MongoDB instance running on localhost:30044, with BSON testing enabled. ```shell uv run pytest --storage memory --mongodb localhost:30044 --use-bson ``` -------------------------------- ### Install MontyDB with BSON support Source: https://github.com/davidlatwe/montydb/blob/master/README.md Installs MontyDB with optional BSON support for using real bson operations. ```sh pip install montydb[bson] ``` ```sh uv pip install montydb[bson] ``` -------------------------------- ### LMDB Configuration Example Source: https://github.com/davidlatwe/montydb/blob/master/README.md Example configuration for the LMDB storage engine, specifying the maximum map size. ```ini [lightning] map_size: 10485760 # Maximum size database may grow to. ``` -------------------------------- ### Run MongoDB Docker Container Source: https://github.com/davidlatwe/montydb/blob/master/README.md Start a MongoDB Docker container for testing purposes. This example shows how to run version 4.4 and map it to localhost port 30044. ```shell docker run --name monty-4.4 -p 30044:27017 -d mongo:4.4 ``` -------------------------------- ### Install MontyDB with LMDB storage Source: https://github.com/davidlatwe/montydb/blob/master/README.md Installs MontyDB with optional LMDB storage engine. ```sh pip install montydb[lmdb] ``` ```sh uv pip install montydb[lmdb] ``` -------------------------------- ### Use MontyList for CRUD Operations Source: https://github.com/davidlatwe/montydb/blob/master/README.md Utilize MontyList, an experimental subclass of list, which combines common CRUD methods found in MongoDB's Collection and Cursor. Example demonstrates finding documents. ```python 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}]) ``` -------------------------------- ### Initialize Flat-File Client Source: https://github.com/davidlatwe/montydb/blob/master/README.md Initializes a MontyDB client using the default flat-file storage engine. An optional step to set storage is shown. ```python from montydb import set_storage, MontyClient set_storage("/db/repo", cache_modified=5) # optional step client = MontyClient("/db/repo") # use current working dir if no path given # ready to go ``` -------------------------------- ### Common Development Commands with uv Source: https://github.com/davidlatwe/montydb/blob/master/README.md Execute common development tasks such as syncing dependencies, running tests, linting, formatting, spell checking, security checks, and building the project using 'uv'. ```bash uv sync uv run pytest . --no-cov uv run ruff check . uv run ruff format . uv run codespell uv run bandit montydb -r uv build ``` -------------------------------- ### Initialize In-Memory Client Source: https://github.com/davidlatwe/montydb/blob/master/README.md Initializes a MontyDB client for in-memory storage. No configuration is needed as nothing is saved to disk. ```python from montydb import MontyClient client = MontyClient(":memory:") # ready to go ``` -------------------------------- ### Basic MontyDB Operations Source: https://github.com/davidlatwe/montydb/blob/master/README.md Demonstrates basic insert and find operations with MontyDB using an in-memory database. ```python >>> 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} ``` -------------------------------- ### Configure SQLite Storage with Options Source: https://github.com/davidlatwe/montydb/blob/master/README.md Configures SQLite storage with specific pragma and connection options. ```python repo = "path_to/repo" set_storage( repository=repo, storage="sqlite", use_bson=True, # sqlite pragma journal_mode="WAL", # sqlite connection option check_same_thread=False, ) client = MontyClient(repo) ... ``` -------------------------------- ### Configure Lightning Storage Source: https://github.com/davidlatwe/montydb/blob/master/README.md Set up MontyDB to use the Lightning Memory-Mapped Database (LMDB) storage engine. This is not the default and requires explicit configuration before initializing the client. ```python from montydb import set_storage, MontyClient set_storage("/db/repo", storage="lightning") # required, to set lightning as engine client = MontyClient("/db/repo") # ready to go ``` -------------------------------- ### Connect using MontyDB URI Source: https://github.com/davidlatwe/montydb/blob/master/README.md Connect to a MontyDB repository by prefixing the path with the 'montydb://' URI scheme. ```python client = MontyClient("montydb:///db/repo") ``` -------------------------------- ### Configure Flat-File Storage Source: https://github.com/davidlatwe/montydb/blob/master/README.md Configures MontyDB to use flat-file storage with specified repository path and cache settings. ```python from montydb import set_storage, MontyClient set_storage( # general settings repository="/db/repo", # dir path for database to live on disk, default is {cwd} storage="flatfile", # storage name, default "flatfile" mongo_version="4.0", # try matching behavior with this mongodb version use_bson=False, # default None, and will import pymongo's bson if None or True # any other kwargs are storage engine settings. cache_modified=10, # the only setting that flat-file have ) # ready to go ``` -------------------------------- ### Dump Data with montydump Source: https://github.com/davidlatwe/montydb/blob/master/README.md Create a binary export (BSON file) from a MontyCollection. This file can be loaded by montyrestore or mongorestore. Requires opening a repository context. ```python from montydb import open_repo, utils with open_repo("foo/bar"): utils.montydump("db", "col", "/data/dump.bson") ``` -------------------------------- ### Run MontyDB Tests with Specific Storage and MongoDB Instance Source: https://github.com/davidlatwe/montydb/blob/master/README.md Execute MontyDB tests using 'uv run pytest', specifying the storage engine and MongoDB instance URL. The '--use-bson' flag can be optionally included for BSON testing. ```shell uv run pytest --storage {storage engin name} --mongodb {mongo instance url} [--use-bson] ``` -------------------------------- ### Configure SQLite Storage Source: https://github.com/davidlatwe/montydb/blob/master/README.md Configures MontyDB to use SQLite as the storage engine, specifying the repository path. ```python from montydb import set_storage, MontyClient set_storage("/db/repo", storage="sqlite") # required, to set sqlite as engine client = MontyClient("/db/repo") # ready to go ``` -------------------------------- ### Restore Data with montyrestore Source: https://github.com/davidlatwe/montydb/blob/master/README.md Load a binary database dump (BSON file) into a MontyCollection. The BSON file can be generated by montydump or mongodump. Requires opening a repository context. ```python from montydb import open_repo, utils with open_repo("foo/bar"): utils.montyrestore("db", "col", "/path/dump.bson") ``` -------------------------------- ### Configure SQLite Write Concern Source: https://github.com/davidlatwe/montydb/blob/master/README.md Sets write concern options for a MontyDB client using SQLite storage. ```python client = MontyClient("/db/repo", synchronous=1, automatic_index=False, busy_timeout=5000) ``` -------------------------------- ### Import Data with montyimport Source: https://github.com/davidlatwe/montydb/blob/master/README.md Import data from an Extended JSON file into a MontyCollection. The JSON file can be generated by montyexport or mongoexport. Requires opening a repository context. ```python from montydb import open_repo, utils with open_repo("foo/bar"): utils.montyimport("db", "col", "/path/dump.json") ``` -------------------------------- ### Export Data with montyexport Source: https://github.com/davidlatwe/montydb/blob/master/README.md Export data from a MontyCollection to a JSON file. This file can be used with montyimport or mongoimport. Requires opening a repository context. ```python from montydb import open_repo, utils with open_repo("foo/bar"): utils.montyexport("db", "col", "/data/dump.json") ``` -------------------------------- ### Record MongoDB Queries with MongoQueryRecorder Source: https://github.com/davidlatwe/montydb/blob/master/README.md Record MongoDB query results over a period using the MongoQueryRecorder utility. This requires access to the database profiler and works by filtering 'find' and 'distinct' command profiles. ```python from pymongo import MongoClient from montydb.utils import MongoQueryRecorder client = MongoClient() recorder = MongoQueryRecorder(client["mydb"]) recorder.start() # Make some queries or run the App... recorder.stop() recorder.extract() {: [, , ...], ...} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.