eventsourcing-mongodb


Nameeventsourcing-mongodb JSON
Version 4.0.0 PyPI version JSON
download
home_page
SummaryAn extension package for the Python Eventsourcing library that provides a persistence module for MongoDB.
upload_time2023-07-14 20:56:48
maintainer
docs_urlNone
authorLuxaaa
requires_python>=3.7
licenseMIT License Copyright (c) 2022 Luxaaa Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords eventsourcing mongodb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Event Sourcing in Python with MongoDB
This is an extension package for the Python
[eventsourcing](https://github.com/pyeventsourcing/eventsourcing) library
that provides a persistence module for [MongoDB](https://www.mongodb.com/).

## Installation
Use pip to install the [stable distribution](https://pypi.org/project/eventsourcing_mongodb/)
from the Python Package Index. Please note, it is recommended to
install Python packages into a Python virtual environment.

    $ pip install eventsourcing-mongodb

## Getting started
Define Aggregates and Applications the usual way. Please refer to the [Eventsourcing Documentation](https://eventsourcing.readthedocs.io/en/stable/) for more detailed examples.
```python
from eventsourcing.domain import Aggregate, event
from eventsourcing.application import Application
from uuid import UUID

class Dog(Aggregate):
    @event('Registered')
    def __init__(self, name: str):
        self.name = name
        self.tricks = []

    @event('TrickAdded')
    def add_trick(self, trick: str):
        self.tricks.append(trick)
    
class DogSchool(Application):
    def register_dog(self, name: str) -> UUID:
        dog = Dog(name)
        self.save(dog)
        return dog.id

    def add_trick(self, dog_id: UUID, trick: str):
        dog = self.repository.get(dog_id)
        dog.add_trick(trick)
        self.save(dog)

    def get_dog(self, dog_id: UUID) -> dict:
        dog = self.repository.get(dog_id)
        return {'id': dog.id, 'name': dog.name, 'tricks': dog.tricks}
```

To configure your Application for using MongoDB for persistence, you need to set the environment variable `PERSISTENCE_MODULE`
to `'eventsourcing_mongodb'`.
Furthermore, you need to set the environment variables `MONGO_CONNECTION_STRING` and `MONGO_DB_NAME`. 
Please refer to the [MongoDB Documentation](https://www.mongodb.com/docs/manual/reference/connection-string/)
to learn more about connection strings. You can read more about the available variables [here](#available-environment-variables) .

```python
import os
os.environ['PERSISTENCE_MODULE'] = 'eventsourcing_mongodb'
os.environ['MONGO_CONNECTION_STRING'] = 'mongodb://localhost'
os.environ['MONGO_DB_NAME'] = 'EventSourcing'
```
Instead of setting the variables on environment level, you can also set them on application level.
```python
class DogSchool(Application):
    env = {
        'PERSISTENCE_MODULE': 'eventsourcing_mongodb',
        'MONGO_CONNECTION_STRING': 'mongodb://localhost',
        'MONGO_DB_NAME': 'EventSourcing',
        ...
    }
    ...
```

Construct and use the application in the usual way.
```python
dog_school = DogSchool()
dog_id = dog_school.register_dog('Fido')
dog_school.add_trick(dog_id, 'roll over')
dog = dog_school.get_dog(dog_id)
print(dog) # {'id': UUID('...'), 'name': 'Fido', 'tricks': ['roll over']}
```
And retrieve the data later:
```python
dog_school = DogSchool()
dog_id = UUID('...')
dog = dog_school.get_dog(dog_id)
print(dog) # {'id': UUID('...'), 'name': 'Fido', 'tricks': ['roll over']}

```

## Available Environment Variables
You can use the following variables to configure mongodb persistence:

| Variable | Type / Possible values | Required | Description |
| --- | --- | --- | --- |
| `PERSISTENCE_MODULE` | `'eventsourcing_mongodb'` | `true` | configures the application to use this module for persistence. 
| `MONGO_CONNECTION_STRING` | string | `true` | MongoDB Connection String. Please refer to the [MongoDB Documentation](https://www.mongodb.com/docs/manual/reference/connection-string/) to learn more about connection strings.
| `MONGO_DB_NAME` | string | `true` | Name of the Database the data sould be stored in
| `MONGO_COL_PREFIX` | string | `false` | Prefix for the MongoDB Collections for events, snapshots and trackings. The default is an empty String.




            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "eventsourcing-mongodb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "eventsourcing,mongodb",
    "author": "Luxaaa",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/a5/c8/2e5e2336bebe4f4a53941d016966905381bce8d1b588a67a8c9820c39d56/eventsourcing-mongodb-4.0.0.tar.gz",
    "platform": null,
    "description": "# Event Sourcing in Python with MongoDB\nThis is an extension package for the Python\n[eventsourcing](https://github.com/pyeventsourcing/eventsourcing) library\nthat provides a persistence module for [MongoDB](https://www.mongodb.com/).\n\n## Installation\nUse pip to install the [stable distribution](https://pypi.org/project/eventsourcing_mongodb/)\nfrom the Python Package Index. Please note, it is recommended to\ninstall Python packages into a Python virtual environment.\n\n    $ pip install eventsourcing-mongodb\n\n## Getting started\nDefine Aggregates and Applications the usual way. Please refer to the [Eventsourcing Documentation](https://eventsourcing.readthedocs.io/en/stable/) for more detailed examples.\n```python\nfrom eventsourcing.domain import Aggregate, event\nfrom eventsourcing.application import Application\nfrom uuid import UUID\n\nclass Dog(Aggregate):\n    @event('Registered')\n    def __init__(self, name: str):\n        self.name = name\n        self.tricks = []\n\n    @event('TrickAdded')\n    def add_trick(self, trick: str):\n        self.tricks.append(trick)\n    \nclass DogSchool(Application):\n    def register_dog(self, name: str) -> UUID:\n        dog = Dog(name)\n        self.save(dog)\n        return dog.id\n\n    def add_trick(self, dog_id: UUID, trick: str):\n        dog = self.repository.get(dog_id)\n        dog.add_trick(trick)\n        self.save(dog)\n\n    def get_dog(self, dog_id: UUID) -> dict:\n        dog = self.repository.get(dog_id)\n        return {'id': dog.id, 'name': dog.name, 'tricks': dog.tricks}\n```\n\nTo configure your Application for using MongoDB for persistence, you need to set the environment variable `PERSISTENCE_MODULE`\nto `'eventsourcing_mongodb'`.\nFurthermore, you need to set the environment variables `MONGO_CONNECTION_STRING` and `MONGO_DB_NAME`. \nPlease refer to the [MongoDB Documentation](https://www.mongodb.com/docs/manual/reference/connection-string/)\nto learn more about connection strings. You can read more about the available variables [here](#available-environment-variables) .\n\n```python\nimport os\nos.environ['PERSISTENCE_MODULE'] = 'eventsourcing_mongodb'\nos.environ['MONGO_CONNECTION_STRING'] = 'mongodb://localhost'\nos.environ['MONGO_DB_NAME'] = 'EventSourcing'\n```\nInstead of setting the variables on environment level, you can also set them on application level.\n```python\nclass DogSchool(Application):\n    env = {\n        'PERSISTENCE_MODULE': 'eventsourcing_mongodb',\n        'MONGO_CONNECTION_STRING': 'mongodb://localhost',\n        'MONGO_DB_NAME': 'EventSourcing',\n        ...\n    }\n    ...\n```\n\nConstruct and use the application in the usual way.\n```python\ndog_school = DogSchool()\ndog_id = dog_school.register_dog('Fido')\ndog_school.add_trick(dog_id, 'roll over')\ndog = dog_school.get_dog(dog_id)\nprint(dog) # {'id': UUID('...'), 'name': 'Fido', 'tricks': ['roll over']}\n```\nAnd retrieve the data later:\n```python\ndog_school = DogSchool()\ndog_id = UUID('...')\ndog = dog_school.get_dog(dog_id)\nprint(dog) # {'id': UUID('...'), 'name': 'Fido', 'tricks': ['roll over']}\n\n```\n\n## Available Environment Variables\nYou can use the following variables to configure mongodb persistence:\n\n| Variable | Type / Possible values | Required | Description |\n| --- | --- | --- | --- |\n| `PERSISTENCE_MODULE` | `'eventsourcing_mongodb'` | `true` | configures the application to use this module for persistence. \n| `MONGO_CONNECTION_STRING` | string | `true` | MongoDB Connection String. Please refer to the [MongoDB Documentation](https://www.mongodb.com/docs/manual/reference/connection-string/) to learn more about connection strings.\n| `MONGO_DB_NAME` | string | `true` | Name of the Database the data sould be stored in\n| `MONGO_COL_PREFIX` | string | `false` | Prefix for the MongoDB Collections for events, snapshots and trackings. The default is an empty String.\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2022 Luxaaa  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "An extension package for the Python Eventsourcing library that provides a persistence module for MongoDB.",
    "version": "4.0.0",
    "project_urls": {
        "Repository": "https://github.com/Luxaaa/eventsourcing-mongodb"
    },
    "split_keywords": [
        "eventsourcing",
        "mongodb"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5804893324d26498241170703b5d48079a4b9a8a8739eaeee6ad0e107dcb434c",
                "md5": "41007068c48e713d4c0e651a36f913cd",
                "sha256": "4aca9d4cd33fbadc2a7fd600c5e2795c086a9c4dd8fd130ce0401fbdbe5f940d"
            },
            "downloads": -1,
            "filename": "eventsourcing_mongodb-4.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "41007068c48e713d4c0e651a36f913cd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8612,
            "upload_time": "2023-07-14T20:56:45",
            "upload_time_iso_8601": "2023-07-14T20:56:45.211544Z",
            "url": "https://files.pythonhosted.org/packages/58/04/893324d26498241170703b5d48079a4b9a8a8739eaeee6ad0e107dcb434c/eventsourcing_mongodb-4.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a5c82e5e2336bebe4f4a53941d016966905381bce8d1b588a67a8c9820c39d56",
                "md5": "7777cd6eac09b4844906c8a436cb9611",
                "sha256": "b0a9f1ff27a8f201460127b177f5581e917ad09ab4e2c964f8c2e4da6dba6a30"
            },
            "downloads": -1,
            "filename": "eventsourcing-mongodb-4.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7777cd6eac09b4844906c8a436cb9611",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8540,
            "upload_time": "2023-07-14T20:56:48",
            "upload_time_iso_8601": "2023-07-14T20:56:48.386249Z",
            "url": "https://files.pythonhosted.org/packages/a5/c8/2e5e2336bebe4f4a53941d016966905381bce8d1b588a67a8c9820c39d56/eventsourcing-mongodb-4.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-14 20:56:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Luxaaa",
    "github_project": "eventsourcing-mongodb",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "eventsourcing-mongodb"
}
        
Elapsed time: 0.09548s