Mongomancy
Description
Project contains abstraction of pymongo driver for automatic reconnect on master switch in remote MongoDB cluster. It
also provides data definition layer.
Core of mongo_driver is the Engine class, handling queries reconnection with notification to registered reconnect
hooks.
Database creates Collections by their definitions. Database hooks itself to engine reconnect event, so it can switch
internal state of database's collections instances.
classDiagram
Executor <|-- Engine : implements
Database o-- Executor
Database *-- Collection
Database o-- CollectionDefinition
Collection o-- Executor
CollectionDefinition *-- Index
CollectionDefinition *-- Document
class Executor{
<<abstract>>
reconnect()
register_hook(reconnect_hook_func)
find_one(collection: pymongo.collection.Collection, ...)
other_collection_methods(collection: pymongo.collection.Collection, ...)
}
class Engine{
+client: MongoClient
-_retry_command(collection, command, ...)
dispose()
reconnect()
register_hook(reconnect_hook_func)
find_one(collection: pymongo.collection.Collection, ...)
other_collection_methods(collection: pymongo.collection.Collection, ...)
}
class Collection{
+dialect_entity: pymongo.collection.Collection
+engine: Executor
+find_one(...)
other_collection_methods()
}
class Document{
+unique_key: Optional[BsonDict]
+data: BsonDict
}
class CollectionDefinition{
+name: str
+indices: Sequence[Index]
+default_docs: Sequence[Document]
}
class Index{
+fields: OrderedDictType[str, Union[str, int]]
+name: Optional[str]
+unique: Optional[bool]
field_for_mongo() -> List[Tuple[str, Union[str, int]]]
}
class Database{
+engine: Executor
+topology: List[types.CollectionDefinition]
-_database: pymongo.database.Database
-_collections: Dict[str, Collection]
invalidate_cache_hook(source: Engine)
get_collection(name: str) -> Collection
extend(*new_definitions: types.CollectionDefinition)
create_all(skip_existing: bool)
ping() -> bool
}
Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
Usage
import logging
from mongomancy import Engine, Database, CollectionDefinition, Index
engine = Engine("localhost", 27017)
logger = logging.getLogger(__name__)
db = Database(engine=engine, logger=logger)
game = CollectionDefinition(name="game", indices=[Index(fields={"genre": 1})])
player = CollectionDefinition(name="player", indices=[Index(fields={"player_id": 1}, unique=True)])
db.add_collection(game)
db.add_collection(player)
db.create_all()
db["game"].find({"genre": "adventure"})
Tests
You can run tests with coverage tracing:
python -m coverage run -m unittest tests/test_* -v
To generate coverage report:
python -m coverage html
Build
Clone repo and set up your pypi repo account credentials on build for build environment.
-
Move to package repo:
cd ~/git/mongomancy
-
Install requirements:
python -m pip install -Ur requirements.txt
-
Clean old build fragments:
rm -rf ./dist ./build ./mongomancy/mongomancy.egg-info
-
Build new package:
python -m build
-
Upload new package:
python -m twine upload dist/*
Metadata
Release files for mongomancy 0.1.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mongomancy-0.1.15.tar.gz | 21.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mongomancy-0.1.15-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.1 kB
Release files / mongomancy-0.1.15.tar.gz
| Download URL | mongomancy-0.1.15.tar.gz |
|---|---|
| Size | 21.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
53a107b4fe641858e9a80a13e14ceb8e3955689037e611b04a9efa987e430030
|
|
BLAKE2b-256 checksum How to use checksums |
9ad6351279a1dc26abe592603661ca6182b4a3414360df51fc5e28953e42d9b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / mongomancy-0.1.15-py3-none-any.whl
| Download URL | mongomancy-0.1.15-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
926c6f8530e067acd84e96bedaaa30b3da1dd6c3533d13952acdf0b359fc837b
|
|
BLAKE2b-256 checksum How to use checksums |
6f56748eeb8bc0ca831cdd32eb14e68a6cf4b76c478a3509551a1fd31fdea470
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|