Package Documentation
=====================
With this library you can map your dictionaries easily, you just need to
pass it:
1- output: the dictionary you want to receive, the variables you want to
map must go with {}
.. code:: python
from DictMaper import MapDict
result = MapDict(
output={
"{var_1}": "Hi! {var_2}, welcome to {company_name}"
"company name":"{company_name}"
}
......
)
2- context: context is the data from which the information will be
obtained:
.. code:: python
from DictMaper import MapDict
result = MapDict(
output={
"{var_1}": "Hi! {var_2}, welcome to {company_name}"
"company name":"{company_name}"
}
context={
"user": {
"name":"user name",
"email":"test_email@..."
}
"company":{
"information":{
"name":"Company name",
"id":"1234"
}
}
}
)
3- vars: vars are the variables you want to map to your output and the
value is where they are located within context:
.. code:: python
from DictMaper import MapDict
result = MapDict(
output={
"{var_1}": "Hi! {var_2}, welcome to {company_name}",
"company":"{company_name}"
}
context={
"user": {
"name":"user name",
"email":"test_email@..."
},
"company":{
"information":{
"name":"Company name",
"id":"1234"
}
}
}
vars={
"var_1": "user.email",
"var_2": "user.name",
"company_name": "company.information.name"
}
)
That’s all, process the data making .process() and as a result you will
have:
.. code:: python
from DictMaper import MapDict
result = MapDict(...).process()
{
"test_email@...": "Hi! user name, welcome to Company name",
"company":"Company name"
}
```
If your context dictionary contains nested dictionaries or lists, you can use this flag variable complex_dict_mapping=True to process more complex dictionaries.
But you must take into account the following restrictions:
1- If the 'context' dictionary contains a key with a list, the name of the key must be the same in the 'vars' dictionary and in the 'output'
2- You can only search at level 1 depth in the keys that contain LISTS in the 'context' dictionary, where the paths defined in the 'variables' dictionary will be searched.
3- It is not possible to place a variable from the 'vars' dictionary in the 'output' dictionary as a key in any of the values of the dictionaries that are within some list that are within the same 'output' dictionary.
Example:
1- output: the dictionary you want to receive, the variables you want to map must go with {}
```python
output = {
"contacts": [{
"name": "{var_name}",
"email": "{var_email}",
"adresses": [{"main address": "{var_main_address}"}]
}],
"company name":"{company_name}"
}
2- context: context is the data from which the information will be
obtained:
.. code:: python
context = {
"contacts": [
{
"name":"user name",
"email":"test_email@...",
"address": {"main": "customer address"}
},
{
"name":"user2 name2",
"email":"test2_email2@...",
"address": {"main": "customer address2"}
}
],
"company":{
"information":{
"name":"Company name",
"id":"1234",
}
}
}
3- vars: vars are the variables you want to map to your output and the
value is where they are located within context:
.. code:: python
vars = {
"contacts": [{
"var_name": "name",
"var_email": "email",
"var_main_address": "address.main",
}],
"company_name": "company.information.name",
}
That’s all, process the data doing .process() and as a result you will
have:
\`\ ``python from DictMaper import MapDict result = MapDict( output=output, context=context, vars=vars, complex_dict_mapping=True ) result.process() { "contacts":[ { "name":"user name", "email":"test_email@...", "adresses":[ { "main address":"customer address" } ] }, { "name":"user2 name2", "email":"test2_email2@...", "adresses":[ { "main address":"customer address2" } ] } ], "company name":"Company name" }``
Raw data
{
"_id": null,
"home_page": "",
"name": "dictmaper",
"maintainer": "Santiago Gonzalez",
"docs_url": null,
"requires_python": "",
"maintainer_email": "alejandro980619@outlook.com",
"keywords": "python,dict,map,data",
"author": "Arnold Blandon and Santiago Gonzalez",
"author_email": "arnold.blandon1@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/06/6a/5ab712aab38cecfe5ffc0aad6c767d767e236437a43f7f80f17b98f620a3/dictmaper-0.0.6.tar.gz",
"platform": null,
"description": "Package Documentation\n=====================\n\nWith this library you can map your dictionaries easily, you just need to\npass it:\n\n1- output: the dictionary you want to receive, the variables you want to\nmap must go with {}\n\n.. code:: python\n\n from DictMaper import MapDict\n result = MapDict(\n output={\n \"{var_1}\": \"Hi! {var_2}, welcome to {company_name}\"\n \"company name\":\"{company_name}\"\n }\n ......\n )\n\n2- context: context is the data from which the information will be\nobtained:\n\n.. code:: python\n\n from DictMaper import MapDict\n result = MapDict(\n output={\n \"{var_1}\": \"Hi! {var_2}, welcome to {company_name}\"\n \"company name\":\"{company_name}\"\n }\n context={\n \"user\": {\n \"name\":\"user name\",\n \"email\":\"test_email@...\"\n }\n \"company\":{\n \"information\":{\n \"name\":\"Company name\",\n \"id\":\"1234\"\n }\n }\n }\n )\n\n3- vars: vars are the variables you want to map to your output and the\nvalue is where they are located within context:\n\n.. code:: python\n\n from DictMaper import MapDict\n result = MapDict(\n output={\n \"{var_1}\": \"Hi! {var_2}, welcome to {company_name}\",\n \"company\":\"{company_name}\"\n }\n context={\n \"user\": {\n \"name\":\"user name\",\n \"email\":\"test_email@...\"\n },\n \"company\":{\n \"information\":{\n \"name\":\"Company name\",\n \"id\":\"1234\"\n }\n }\n }\n vars={\n \"var_1\": \"user.email\",\n \"var_2\": \"user.name\",\n \"company_name\": \"company.information.name\"\n }\n )\n\nThat\u2019s all, process the data making .process() and as a result you will\nhave:\n\n.. code:: python\n\n from DictMaper import MapDict\n result = MapDict(...).process()\n {\n \"test_email@...\": \"Hi! user name, welcome to Company name\",\n \"company\":\"Company name\"\n }\n ```\n\n If your context dictionary contains nested dictionaries or lists, you can use this flag variable complex_dict_mapping=True to process more complex dictionaries.\n But you must take into account the following restrictions:\n 1- If the 'context' dictionary contains a key with a list, the name of the key must be the same in the 'vars' dictionary and in the 'output'\n 2- You can only search at level 1 depth in the keys that contain LISTS in the 'context' dictionary, where the paths defined in the 'variables' dictionary will be searched.\n 3- It is not possible to place a variable from the 'vars' dictionary in the 'output' dictionary as a key in any of the values \u200b\u200bof the dictionaries that are within some list that are within the same 'output' dictionary.\n\n Example:\n 1- output: the dictionary you want to receive, the variables you want to map must go with {}\n ```python\n output = {\n \"contacts\": [{\n \"name\": \"{var_name}\",\n \"email\": \"{var_email}\",\n \"adresses\": [{\"main address\": \"{var_main_address}\"}]\n }],\n \"company name\":\"{company_name}\"\n }\n\n2- context: context is the data from which the information will be\nobtained:\n\n.. code:: python\n\n context = {\n \"contacts\": [\n {\n \"name\":\"user name\",\n \"email\":\"test_email@...\",\n \"address\": {\"main\": \"customer address\"}\n },\n {\n \"name\":\"user2 name2\",\n \"email\":\"test2_email2@...\",\n \"address\": {\"main\": \"customer address2\"}\n }\n ],\n \"company\":{\n \"information\":{\n \"name\":\"Company name\",\n \"id\":\"1234\",\n }\n }\n }\n\n3- vars: vars are the variables you want to map to your output and the\nvalue is where they are located within context:\n\n.. code:: python\n\n vars = {\n \"contacts\": [{\n \"var_name\": \"name\",\n \"var_email\": \"email\",\n \"var_main_address\": \"address.main\",\n }],\n \"company_name\": \"company.information.name\",\n }\n\nThat\u2019s all, process the data doing .process() and as a result you will\nhave:\n\\`\\ ``python from DictMaper import MapDict result = MapDict( output=output, context=context, vars=vars, complex_dict_mapping=True ) result.process() { \"contacts\":[ { \"name\":\"user name\", \"email\":\"test_email@...\", \"adresses\":[ { \"main address\":\"customer address\" } ] }, { \"name\":\"user2 name2\", \"email\":\"test2_email2@...\", \"adresses\":[ { \"main address\":\"customer address2\" } ] } ], \"company name\":\"Company name\" }``\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Library created to map keys in dictionaries.",
"version": "0.0.6",
"project_urls": null,
"split_keywords": [
"python",
"dict",
"map",
"data"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "235e8868b6a6443c01ef6612de11450c84b2dac3420de3fc532839833866455a",
"md5": "5bacb10e227eb9b249a096022853afa9",
"sha256": "792bc28b8b6e6563a9f6309758a5a8d3ac38ccf946ad22fd79d12dacd0207c37"
},
"downloads": -1,
"filename": "dictmaper-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5bacb10e227eb9b249a096022853afa9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7358,
"upload_time": "2023-11-08T17:50:39",
"upload_time_iso_8601": "2023-11-08T17:50:39.217494Z",
"url": "https://files.pythonhosted.org/packages/23/5e/8868b6a6443c01ef6612de11450c84b2dac3420de3fc532839833866455a/dictmaper-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "066a5ab712aab38cecfe5ffc0aad6c767d767e236437a43f7f80f17b98f620a3",
"md5": "64c872339c7a77e76a8425d6bf1edcae",
"sha256": "f4d3ea4c34fd97195aa87d8f5f0194fef5d793cb284a946bd3486d75c3171eca"
},
"downloads": -1,
"filename": "dictmaper-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "64c872339c7a77e76a8425d6bf1edcae",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4232,
"upload_time": "2023-11-08T17:50:41",
"upload_time_iso_8601": "2023-11-08T17:50:41.237530Z",
"url": "https://files.pythonhosted.org/packages/06/6a/5ab712aab38cecfe5ffc0aad6c767d767e236437a43f7f80f17b98f620a3/dictmaper-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-08 17:50:41",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "dictmaper"
}