mongomancy


Namemongomancy JSON
Version 0.1.15 PyPI version JSON
download
home_pageNone
SummaryPymongo based python client with data definition layer.
upload_time2024-10-30 10:51:04
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseGNU General Public License v3 (GPLv3)
keywords mongo python pymongo database nosql
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Mongomancy

[![codecov](https://codecov.io/gh/Ryu-CZ/mongomancy/graph/badge.svg?token=3WT6TSHPPQ)](https://codecov.io/gh/Ryu-CZ/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 `Collection`s by their definitions. Database hooks itself to engine reconnect event, so it can switch
internal state of database's collections instances.

```mermaid
    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

```python
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:

```shell
python -m coverage run -m unittest tests/test_* -v 
```

To generate coverage report:

```shell
python -m coverage html   
```

## Build

Clone repo and set up your pypi repo account credentials on build for build environment.

- Move to package repo:

    ```shell
    cd ~/git/mongomancy
    ```

- Install requirements:

   ```shell
   python -m pip install -Ur requirements.txt
   ```

- Clean old build fragments:

    ```shell
    rm -rf ./dist ./build ./mongomancy/mongomancy.egg-info
    ```

- Build new package:

    ```shell
    python -m build
    ``` 

- Upload new package:

    ```shell
    python -m twine upload dist/* 
    ```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "mongomancy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "mongo, python, pymongo, database, nosql",
    "author": null,
    "author_email": "Tom Trval <thandeus@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/9a/d6/351279a1dc26abe592603661ca6182b4a3414360df51fc5e28953e42d9b2/mongomancy-0.1.15.tar.gz",
    "platform": null,
    "description": "# Mongomancy\n\n[![codecov](https://codecov.io/gh/Ryu-CZ/mongomancy/graph/badge.svg?token=3WT6TSHPPQ)](https://codecov.io/gh/Ryu-CZ/mongomancy)\n\n## Description\n\nProject contains abstraction of `pymongo` driver for automatic reconnect on master switch in remote MongoDB cluster. It\nalso provides data definition layer.\n\nCore of `mongo_driver` is the `Engine` class, handling queries reconnection with notification to registered reconnect\nhooks.\n`Database` creates `Collection`s by their definitions. Database hooks itself to engine reconnect event, so it can switch\ninternal state of database's collections instances.\n\n```mermaid\n    classDiagram\n        Executor <|-- Engine : implements\n        Database o-- Executor\n        Database *-- Collection\n        Database o-- CollectionDefinition\n        Collection o-- Executor\n        CollectionDefinition *-- Index\n        CollectionDefinition *-- Document\n        \n        class Executor{\n            <<abstract>>\n            reconnect()\n            register_hook(reconnect_hook_func)\n            find_one(collection: pymongo.collection.Collection, ...)\n            other_collection_methods(collection: pymongo.collection.Collection, ...)\n        }\n        \n        class Engine{\n            +client: MongoClient\n            -_retry_command(collection, command, ...)\n            dispose()\n            reconnect()\n            register_hook(reconnect_hook_func)\n            find_one(collection: pymongo.collection.Collection, ...)\n            other_collection_methods(collection: pymongo.collection.Collection, ...)\n        }\n    \n        class Collection{\n            +dialect_entity: pymongo.collection.Collection\n            +engine: Executor\n            +find_one(...)\n            other_collection_methods()\n        }\n        \n        class Document{\n            +unique_key: Optional[BsonDict]\n            +data: BsonDict\n        }\n    \n        class CollectionDefinition{\n            +name: str\n            +indices: Sequence[Index]\n            +default_docs: Sequence[Document]\n        }\n    \n        class Index{\n            +fields: OrderedDictType[str, Union[str, int]]\n            +name: Optional[str]\n            +unique: Optional[bool]\n            field_for_mongo() -> List[Tuple[str, Union[str, int]]]\n        }\n    \n        class Database{\n            +engine: Executor\n            +topology: List[types.CollectionDefinition]\n            -_database: pymongo.database.Database\n            -_collections: Dict[str, Collection]\n            invalidate_cache_hook(source: Engine) \n            get_collection(name: str) -> Collection\n            extend(*new_definitions: types.CollectionDefinition)\n            create_all(skip_existing: bool)\n            ping() -> bool\n        }\n```\n\n## Installation\n\nWithin a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew.\nHowever, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing\nspecific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a\nspecific context like a particular programming language version or operating system or has dependencies that have to be\ninstalled manually, also add a Requirements subsection.\n\n## Usage\n\n```python\nimport logging\nfrom mongomancy import Engine, Database, CollectionDefinition, Index\n\nengine = Engine(\"localhost\", 27017)\nlogger = logging.getLogger(__name__)\ndb = Database(engine=engine, logger=logger)\ngame = CollectionDefinition(name=\"game\", indices=[Index(fields={\"genre\": 1})])\nplayer = CollectionDefinition(name=\"player\", indices=[Index(fields={\"player_id\": 1}, unique=True)])\ndb.add_collection(game)\ndb.add_collection(player)\ndb.create_all()\ndb[\"game\"].find({\"genre\": \"adventure\"})\n```\n\n## Tests\n\nYou can run tests with coverage tracing:\n\n```shell\npython -m coverage run -m unittest tests/test_* -v \n```\n\nTo generate coverage report:\n\n```shell\npython -m coverage html   \n```\n\n## Build\n\nClone repo and set up your pypi repo account credentials on build for build environment.\n\n- Move to package repo:\n\n    ```shell\n    cd ~/git/mongomancy\n    ```\n\n- Install requirements:\n\n   ```shell\n   python -m pip install -Ur requirements.txt\n   ```\n\n- Clean old build fragments:\n\n    ```shell\n    rm -rf ./dist ./build ./mongomancy/mongomancy.egg-info\n    ```\n\n- Build new package:\n\n    ```shell\n    python -m build\n    ``` \n\n- Upload new package:\n\n    ```shell\n    python -m twine upload dist/* \n    ```\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3 (GPLv3)",
    "summary": "Pymongo based python client with data definition layer.",
    "version": "0.1.15",
    "project_urls": {
        "Bug Tracker": "https://github.com/Ryu-CZ/mongomancy/issues",
        "Homepage": "https://github.com/Ryu-CZ/mongomancy"
    },
    "split_keywords": [
        "mongo",
        " python",
        " pymongo",
        " database",
        " nosql"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6f56748eeb8bc0ca831cdd32eb14e68a6cf4b76c478a3509551a1fd31fdea470",
                "md5": "d22d81d0244d302b72366f74acbf808b",
                "sha256": "926c6f8530e067acd84e96bedaaa30b3da1dd6c3533d13952acdf0b359fc837b"
            },
            "downloads": -1,
            "filename": "mongomancy-0.1.15-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d22d81d0244d302b72366f74acbf808b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 14786,
            "upload_time": "2024-10-30T10:51:02",
            "upload_time_iso_8601": "2024-10-30T10:51:02.747588Z",
            "url": "https://files.pythonhosted.org/packages/6f/56/748eeb8bc0ca831cdd32eb14e68a6cf4b76c478a3509551a1fd31fdea470/mongomancy-0.1.15-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9ad6351279a1dc26abe592603661ca6182b4a3414360df51fc5e28953e42d9b2",
                "md5": "6a833e291e518016bd2354d32c89fec3",
                "sha256": "53a107b4fe641858e9a80a13e14ceb8e3955689037e611b04a9efa987e430030"
            },
            "downloads": -1,
            "filename": "mongomancy-0.1.15.tar.gz",
            "has_sig": false,
            "md5_digest": "6a833e291e518016bd2354d32c89fec3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 21339,
            "upload_time": "2024-10-30T10:51:04",
            "upload_time_iso_8601": "2024-10-30T10:51:04.275070Z",
            "url": "https://files.pythonhosted.org/packages/9a/d6/351279a1dc26abe592603661ca6182b4a3414360df51fc5e28953e42d9b2/mongomancy-0.1.15.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-30 10:51:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Ryu-CZ",
    "github_project": "mongomancy",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "mongomancy"
}
        
Elapsed time: 0.37798s