{"id":26355716,"url":"https://github.com/aitechnologies-it/dlib","last_synced_at":"2025-07-09T23:32:38.249Z","repository":{"id":50465298,"uuid":"359476986","full_name":"aitechnologies-it/dlib","owner":"aitechnologies-it","description":"The python dictionary library.","archived":false,"fork":false,"pushed_at":"2024-08-21T12:10:22.000Z","size":54,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-19T20:18:30.466Z","etag":null,"topics":["dict","dictionary","json","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aitechnologies-it.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-19T13:51:55.000Z","updated_at":"2024-08-21T12:07:22.000Z","dependencies_parsed_at":"2024-08-21T13:27:56.883Z","dependency_job_id":"461c178c-5e6e-4043-bbe7-03a1a12858c9","html_url":"https://github.com/aitechnologies-it/dlib","commit_stats":{"total_commits":40,"total_committers":3,"mean_commits":"13.333333333333334","dds":0.575,"last_synced_commit":"bb3a3b5342cfe7abdabeabe5490e214dd5121802"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/aitechnologies-it/dlib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aitechnologies-it%2Fdlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aitechnologies-it%2Fdlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aitechnologies-it%2Fdlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aitechnologies-it%2Fdlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aitechnologies-it","download_url":"https://codeload.github.com/aitechnologies-it/dlib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aitechnologies-it%2Fdlib/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264505262,"owners_count":23618910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dict","dictionary","json","python"],"created_at":"2025-03-16T13:17:30.387Z","updated_at":"2025-07-09T23:32:38.233Z","avatar_url":"https://github.com/aitechnologies-it.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :yarn: pydlib [![Downloads](https://pepy.tech/badge/pydlib)](https://pepy.tech/project/pydlib)\nThe **py**thon **d**ictionary **lib**rary to get into complex nested python dictionary structures (e.g. json) in a safe and clean way. We take inspiration from Greek myth of Minotaur, where Ariadne with the help of a thread escaped the labyrinth with his beloved Theseus.\n\n## Why use pydlib\n\nSometimes you have to navigate deep json dicts from remote sources, like elastic logs: you can make a series of ```.get()``` and check for ```None``` every time; or you can do ```obj[\"path\"][\"to\"][\"nested\"][\"field\"]``` and wrap everything in a ```try/except```...\n\nOr you can use ```pydlib``` and write:\n\n```python\npydlib.get(obj, \"path.to.nested.field\")\n```\n\nto get the value of ```field```, or ```None``` if anything is not a ```dict``` along the given path.\n\n## Installation\n\nTo install **pydlib**, simply use `pip`:\n\n```bash\n$ pip install pydlib\n```\n\nor install from the repository:\n\n```bash\n$ git clone https://github.com/aitechnologies-it/dlib.git\n$ cd dlib\n$ python setup.py install\n```\n\n## Basic usage\n\n### get()\n\nYou can **get** the value from a nested field, just by indicating the path to the nested sub-structure as follows:\n\n```python\n\u003e\u003e\u003e import pydlib as dl\n\n\u003e\u003e\u003e dictionary = {\n\u003e\u003e\u003e   'path': {\n\u003e\u003e\u003e       'to': {\n\u003e\u003e\u003e          'nested': {\n\u003e\u003e\u003e             'field': 42\n\u003e\u003e\u003e           }\n\u003e\u003e\u003e        }\n\u003e\u003e\u003e    }\n\u003e\u003e\u003e }\n\u003e\u003e\u003e dl.get(dictionary, path='path.to.nested.field', default=0)\n42\n```\n\nInstead, if the field we are looking for doesn't exists, or, if it exists but has a None value, then:\n\n```python\n\u003e\u003e\u003e ...\n\u003e\u003e\u003e dl.get(dictionary, path='path.to.nested.nonexisting.field', default=0)\n0\n```\n\n### has()\n\nYou can also test for a field simply calling:\n\n```python\n\u003e\u003e\u003e import pydlib as dl\n\n\u003e\u003e\u003e dictionary = { ... }\n\u003e\u003e\u003e dl.has(dictionary, path='path.to.nested.field')\nTrue\n```\n\n### update()\n\nFurthermore, the **pydlib** comes with built-in functions to also **update** and **delete** fields. For example, to **update**:\n\n```python\n\u003e\u003e\u003e import pydlib as dl\n\n\u003e\u003e\u003e dictionary = { ... }\n\u003e\u003e\u003e dl.update(dictionary, path='path.to.nested.field', value=1)\n{\n   'path': {\n       'to': {\n          'nested': {\n             'field': 1\n           }\n        }\n    }\n}\n```\n\n### delete()\n\nInstead, to **delete**:\n\n```python\n\u003e\u003e\u003e import pydlib as dl\n\n\u003e\u003e\u003e dictionary = { ... }\n\u003e\u003e\u003e dl.delete(dictionary, path='path.to.nested.field')\n{\n   'path': {\n       'to': {\n          'nested': {}\n        }\n    }\n}\n```\n\n### Type-safety\n\npydlib is **type safe**, in fact you don't have to manually check the type of inputs, **pydlib** does it for you:\n\n```python\n\u003e\u003e\u003e import pydlib as dl\n\n\u003e\u003e\u003e res = dl.get(\"not a dictionary\", path=\"nowhere\", default=None)\n\u003e\u003e\u003e res is None\nTrue\n```\n\n## Advanced features\n\n### Custom separator\n\nIt may happen that a dictionary has a string key with `.` in it. In this case you should use a different separator:\n\n```python\n\u003e\u003e\u003e import pydlib as dl\n\n\u003e\u003e\u003e d = {\"a\": {\"b.c\": 42}}\n\n# Separator conflict\n\u003e\u003e\u003e dl.get(d, \"a.b.c\")\nNone\n\n# This works!\n\u003e\u003e\u003e dl.get(d, \"a/b.c\", sep=\"/\")\n42\n```\n\n### Search inside lists\n\n```has()``` and ```get()``` (but not ```update``` and ```delete```!) can handle lists. This means that, if a list is encountered, the search for the rest of the path continues for each element of the list. A few examples are needed:\n\n- ```b``` is a list, get() will return a list with all dictionaries containing the rest of the path ```c.d```:\n\n    ```python\n    \u003e\u003e\u003e d = {\"a\":\n                {\"b\": [\n                    {\"c\":   {\"d\":   1}}, # \u003c-- this\n                    {\"bad\": {\"d\":   2}},\n                    {\"c\":   {\"d\":   3}}, # \u003c-- this\n                    {\"c\":   {\"bad\": 4}}\n                ]\n            }\n        }\n\n    \u003e\u003e\u003e dl.get(d, \"a.b.c.d\")\n    [1, 3]\n    ```\n- this works also for nested lists. In this case a nested list of matching depth is returned:\n\n    ```python\n    \u003e\u003e\u003e d = {\"a\":\n                {\"b\": [\n                    {\"c\":\n                        {\"d\": [\n                            {\"e\":   1},\n                            {\"e\":   2},\n                            {\"bad\": 3},\n                        ]}\n                    },\n                    {\"bad\":\n                        {\"d\": [\n                            {\"e\":   4},\n                        ]}\n                    },\n                    {\"c\":\n                        {\"d\": [\n                            {\"e\": 5},\n                        ]}\n                    },\n                ]\n            }\n        }\n\n    \u003e\u003e\u003e dl.get(d, \"a.b.c.d.e\")\n    [[1, 2], [5]]\n    ```\n\n- In this case the elements of list ```b``` are of different types, ```(1)``` and ```(3)``` are dictionaries, ```(2)``` is a list:\n    ```python\n    \u003e\u003e\u003e d = {\"a\":\n                {\"b\": [\n                    {\"c\": {\"d\": 1}},     # (1)\n                    [ {\"c\": {\"d\": 3}} ], # (2)\n                    {\"c\": {\"d\": 4}},     # (3)\n                ]\n            }\n        }\n\n    \u003e\u003e\u003e dl.get(d, \"a.b.c.d\")\n    [1, [3], 4]\n    ```\n\n- Handling of lists can be disabled by setting ```search_lists=False```. Here's different behaviours for ```search_lists```:\n    ```python\n    \u003e\u003e\u003e d = {\"a\":\n                {\"b\": [\n                    {\"c\":   {\"d\":   1}},\n                    {\"bad\": {\"d\":   2}},\n                    {\"c\":   {\"d\":   3}},\n                    {\"c\":   {\"bad\": 4}}\n                ]\n            }\n        }\n\n    \u003e\u003e\u003e dl.get(d, \"a.b.c.d\", search_lists=True)\n    [1, 3]\n    \u003e\u003e\u003e dl.get(d, \"a.b.c.d\", search_lists=False)\n    None\n\n    # But if instead we want to get `a.b`, no lists are traversed and both return the value of `b`\n    \u003e\u003e\u003e dl.get(d, \"a.b\", search_lists=True)\n    [{'c': {'d': 1}}, [{'c': {'d': 3}}], {'c': {'d': 4}}]\n    \u003e\u003e\u003e dl.get(d, \"a.b\", search_lists=False)\n    [{'c': {'d': 1}}, [{'c': {'d': 3}}], {'c': {'d': 4}}]\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faitechnologies-it%2Fdlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faitechnologies-it%2Fdlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faitechnologies-it%2Fdlib/lists"}