Skip to main content

Pymongo based python client with data definition layer.

Project description

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{
            +mongo_collection: 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"})

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

mongomancy-0.1.2.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

mongomancy-0.1.2-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file mongomancy-0.1.2.tar.gz.

File metadata

  • Download URL: mongomancy-0.1.2.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for mongomancy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2433ba4ee899384f05834b20d2c773832bd7799bcf951fed284a44539156220f
MD5 4fa29548a2d4607de95e6c6d2ac92bb4
BLAKE2b-256 84bee88f601b11dda73f8d283e8c3d1a7e053d28a17446aeb63dd65a2cde1527

See more details on using hashes here.

File details

Details for the file mongomancy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mongomancy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for mongomancy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a283941d9eb8ed3f434cbc307edadd28fbade56ddfdee21895ab56a028d5bdb6
MD5 fa56f9021d90068d187f7751fe0a3654
BLAKE2b-256 085572e4ed2881385917656ecc0132aa3f812d41e7571dc87a2b17d647266b85

See more details on using hashes here.

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