mapperr


Namemapperr JSON
Version 0.2.4 PyPI version JSON
download
home_pagehttps://github.com/mujdecisy/mapperr
Summarymapperr for mapping across dict and object, recursively
upload_time2023-08-27 21:22:24
maintainer
docs_urlNone
authormujdecisy
requires_python
license
keywords python mapper recursive mapping
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # **mapperr - mapping across dictionary and class object, recursively**

If you are using python for implementing protocols, cache management, nosql or sql database manupilation with  the object oriented concepts in your code, mapperr can handle your object in your way, easily.

## Installation
`via pip`
```shell
pip3 install mapperr
```
`via direct setup`
```shell
pip3 install setuptools
python3 setup.py sdist bdist_wheel
pip3 install dist/mapperr-0.0.1-py3-none-any.whl
```

## Usage
Your classes' attributes are needed to be annotated with their types like `int`, `str`, `Book`, `List[Book]`. Parameterized constructors are not suitable, you can use it with plain objects which has most trash work. You can also fill your required options with param `op_required` as string list.

**`to_obj( dict_data: dict, destination_class: Type ) -> object`**

**`to_dict( obj: object ) -> dict`**


```python
from typing import List
from pprint import pprint
from mapperr import to_dict, to_obj

class Book:
    _id: int
    title: str
    op_required: list = ['_id', 'title']

class BookShelf:
    code: str
    books: List[Book]

class Library:
    name: str
    book_shelfs: List[BookShelf]


def retrieve_library_from_the_source() -> dict:
    return {
        "name" : "Hogwarts Library",
        "book_shelfs" : [
            {
                "code" : "A1",
                "books" : [
                    {
                    "_id" : 0,
                    "title" : "Defence Against the Dark Arts"
                    },
                    {
                    "_id" : 1,
                    "title" : "Potions"
                    },
                ]
            },
            {
                "code" : "A2",
                "books" : [
                    {
                    "_id" : 3,
                    "title" : "Charms"
                    },
                    {
                    "_id" : 4,
                    "title" : "Herbology"
                    },
                ]
            }
        ]
    }

def send_library_to_the_source(data: dict):
    pprint(data)


lib: Library = to_obj(retrieve_library_from_the_source(), Library)

new_book = Book()
new_book._id = 5
new_book.title = "Alchemy"

lib.book_shelfs[0].books.append(new_book)

send_library_to_the_source( to_dict(lib) )
```

You can add your `recursive` type definitions into your class by using string variables and you can also use `superclass`es.

```python
class Person:
    name: str
    identity: int
    age: int
    mother: 'Person'
    father: 'Person'
    friends: List['Person']

class Employee(Person):
    company_name: str
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mujdecisy/mapperr",
    "name": "mapperr",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,mapper,recursive mapping",
    "author": "mujdecisy",
    "author_email": "mujdecisy@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/dd/81/896a4aa7d32c1d14d322c76344929db956a5ffaa7509afa7ebd3beb8bf72/mapperr-0.2.4.tar.gz",
    "platform": null,
    "description": "# **mapperr - mapping across dictionary and class object, recursively**\n\nIf you are using python for implementing protocols, cache management, nosql or sql database manupilation with  the object oriented concepts in your code, mapperr can handle your object in your way, easily.\n\n## Installation\n`via pip`\n```shell\npip3 install mapperr\n```\n`via direct setup`\n```shell\npip3 install setuptools\npython3 setup.py sdist bdist_wheel\npip3 install dist/mapperr-0.0.1-py3-none-any.whl\n```\n\n## Usage\nYour classes' attributes are needed to be annotated with their types like `int`, `str`, `Book`, `List[Book]`. Parameterized constructors are not suitable, you can use it with plain objects which has most trash work. You can also fill your required options with param `op_required` as string list.\n\n**`to_obj( dict_data: dict, destination_class: Type ) -> object`**\n\n**`to_dict( obj: object ) -> dict`**\n\n\n```python\nfrom typing import List\nfrom pprint import pprint\nfrom mapperr import to_dict, to_obj\n\nclass Book:\n    _id: int\n    title: str\n    op_required: list = ['_id', 'title']\n\nclass BookShelf:\n    code: str\n    books: List[Book]\n\nclass Library:\n    name: str\n    book_shelfs: List[BookShelf]\n\n\ndef retrieve_library_from_the_source() -> dict:\n    return {\n        \"name\" : \"Hogwarts Library\",\n        \"book_shelfs\" : [\n            {\n                \"code\" : \"A1\",\n                \"books\" : [\n                    {\n                    \"_id\" : 0,\n                    \"title\" : \"Defence Against the Dark Arts\"\n                    },\n                    {\n                    \"_id\" : 1,\n                    \"title\" : \"Potions\"\n                    },\n                ]\n            },\n            {\n                \"code\" : \"A2\",\n                \"books\" : [\n                    {\n                    \"_id\" : 3,\n                    \"title\" : \"Charms\"\n                    },\n                    {\n                    \"_id\" : 4,\n                    \"title\" : \"Herbology\"\n                    },\n                ]\n            }\n        ]\n    }\n\ndef send_library_to_the_source(data: dict):\n    pprint(data)\n\n\nlib: Library = to_obj(retrieve_library_from_the_source(), Library)\n\nnew_book = Book()\nnew_book._id = 5\nnew_book.title = \"Alchemy\"\n\nlib.book_shelfs[0].books.append(new_book)\n\nsend_library_to_the_source( to_dict(lib) )\n```\n\nYou can add your `recursive` type definitions into your class by using string variables and you can also use `superclass`es.\n\n```python\nclass Person:\n    name: str\n    identity: int\n    age: int\n    mother: 'Person'\n    father: 'Person'\n    friends: List['Person']\n\nclass Employee(Person):\n    company_name: str\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "mapperr for mapping across dict and object, recursively",
    "version": "0.2.4",
    "project_urls": {
        "Homepage": "https://github.com/mujdecisy/mapperr"
    },
    "split_keywords": [
        "python",
        "mapper",
        "recursive mapping"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dd81896a4aa7d32c1d14d322c76344929db956a5ffaa7509afa7ebd3beb8bf72",
                "md5": "127754a6e759831960b094cf79dca358",
                "sha256": "d8f68175f1fda88d96776343e7cf9678714b6455956f1c1f948ed22e3ff014f1"
            },
            "downloads": -1,
            "filename": "mapperr-0.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "127754a6e759831960b094cf79dca358",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6306,
            "upload_time": "2023-08-27T21:22:24",
            "upload_time_iso_8601": "2023-08-27T21:22:24.809896Z",
            "url": "https://files.pythonhosted.org/packages/dd/81/896a4aa7d32c1d14d322c76344929db956a5ffaa7509afa7ebd3beb8bf72/mapperr-0.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-27 21:22:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mujdecisy",
    "github_project": "mapperr",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mapperr"
}
        
Elapsed time: 0.10586s