{"id":13606647,"url":"https://github.com/carlosescri/DottedDict","last_synced_at":"2025-04-12T08:31:47.272Z","repository":{"id":14801051,"uuid":"17523247","full_name":"carlosescri/DottedDict","owner":"carlosescri","description":"Python library that provides a method of accessing lists and dicts with a dotted path notation.","archived":false,"fork":false,"pushed_at":"2024-12-09T14:16:33.000Z","size":35,"stargazers_count":201,"open_issues_count":9,"forks_count":25,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-08T09:11:09.748Z","etag":null,"topics":[],"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/carlosescri.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.txt","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":"2014-03-07T18:29:00.000Z","updated_at":"2025-04-06T07:26:06.000Z","dependencies_parsed_at":"2024-01-05T21:18:45.167Z","dependency_job_id":"2c1e1ea0-7dbe-495e-95f3-7527fef40867","html_url":"https://github.com/carlosescri/DottedDict","commit_stats":{"total_commits":29,"total_committers":5,"mean_commits":5.8,"dds":0.6896551724137931,"last_synced_commit":"fa1cba43f414871d0f6978487d61b8760fda4a68"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosescri%2FDottedDict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosescri%2FDottedDict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosescri%2FDottedDict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosescri%2FDottedDict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/carlosescri","download_url":"https://codeload.github.com/carlosescri/DottedDict/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248539960,"owners_count":21121264,"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":[],"created_at":"2024-08-01T19:01:11.074Z","updated_at":"2025-04-12T08:31:42.259Z","avatar_url":"https://github.com/carlosescri.png","language":"Python","funding_links":[],"categories":["Built-in Classes Enhancement","Python","内置类增强功能","内置类的增强版实现","Built-in Classes Enhancement [🔝](#readme)","资源列表","Awesome Python"],"sub_categories":["内置类的增强版实现","Built-in Classes Enhancement"],"readme":"dotted\n======\n\n.. image:: https://pypip.in/version/dotted/badge.svg?style=flat\n    :target: https://pypi.python.org/pypi/dotted/\n    :alt: Latest Version\n.. image:: https://travis-ci.org/carlosescri/DottedDict.svg?branch=master\n    :target: https://travis-ci.org/carlosescri/DottedDict\n\nA Python library that provides a method of accessing lists and dicts with a\ndotted path notation. It is useful to access a deep path inside a complex\nobject composed of lists and dicts.\n\nQuick \u0026 Dirty:\n==============\n\n.. code-block:: python\n\n    from dotted.collection import DottedCollection, DottedDict, DottedList\n\n    obj = DottedCollection.factory(dict_or_list)\n    obj = DottedCollection.load_json(json_value)\n    obj = DottedDict(a_dict)\n    obj = DottedList(a_list)\n\n    from dotted.utils import dot, dot_json\n\n    obj = dot(dict_or_list)\n    obj = dot_json(json_value)\n\n``DottedDict`` and ``DottedList`` have the same accessors as ``dict`` and ``list``\nso you can iterate them as usual. Both type of objects support access via a\ndotted path key.\n\nExamples\n========\n\nExample #1: DottedList\n----------------------\n\n.. code-block:: python\n\n    obj = DottedList([0, 1, 2, 3, [4, 5, 6], 7, 8, [9, 10]])\n\nAll of these are true:\n\n.. code-block:: python\n\n    obj[0]     ==  0\n    obj['1']   ==  1\n    obj['4.0'] ==  4\n    obj['4.2'] ==  6\n    obj[5]     ==  7\n    obj['7.1'] == 10\n\nIf you want to append you can do:\n\n.. code-block:: python\n\n    obj.append(12)\n\nor:\n\n.. code-block:: python\n\n    obj[8] = 11\n\nbut the latter only works if ``index == len(obj)``. In other case you will get a\nvery pretty exception.\n\nExample #2: DottedDict\n----------------------\n\n.. code-block:: python\n\n    obj = DottedDict({'hello': {'world': {'wide': 'web'}}})\n\nAll of these are true:\n\n.. code-block:: python\n\n    obj['hello'] == {'world': {'wide': 'web'}}\n    obj['hello.world'] == {'wide': 'web'}\n    obj['hello.world.wide'] == 'web'\n\n    obj.hello == {'world': {'wide': 'web'}}\n    obj.hello.world == {'wide': 'web'}\n    obj.hello.world.wide == 'web'\n\nExample #3: Both working together\n---------------------------------\n\n.. code-block:: python\n\n    obj = DottedCollection.factory({\n        'hello': [{'world': {'wide': ['web', 'web', 'web']}}]\n    })\n\nYou can access:\n\n.. code-block:: python\n\n    obj['hello'][0]['world']['wide'][0]\n    obj.hello[0].world.wide[0]\n    obj.hello[0].world['wide'][0]\n    obj.hello[0].world['wide.0']\n    obj.hello['0.world'].wide[0]\n    ...\n    obj['hello.0.world.wide.0']\n\nExample #4: When new values are dicts or lists\n----------------------------------------------\n\n.. code-block:: python\n\n    obj = DottedCollection.factory(some_obj)\n\n    obj['some.path'] = {'hello': 'world'}  # will be converted to a DottedDict\n    obj['another.path'] = ['hello']  # will be converted to a DottedList\n\nExample #5: Shortcuts\n---------------------\n\n.. code-block:: python\n\n    from dotted.utils import dot, dot_json\n\n    obj = dot({'hello': 'world'})\n    obj = dot_json('{\"hello\": \"world\"}')\n\nExample #6: Keys with dots inside!\n----------------------------------\n\nWell, you can actually use escaped keys, but it's better to avoid them:\n\n.. code-block:: python\n\n    from dotted.utils import dot, dot_json\n    obj = dot({\"hello\\.world\": \"Hello!\"})\n    obj = dot_json('{\"hello\\\\\\\\.world\": \"Hello!\"}')\n    value = obj[\"hello\\.world\"]  # Hello!\n\nThat's all!\n\nTests\n=====\n\nRun in the terminal from the parent directory:\n\n.. code-block:: console\n\n    python -m dotted.test.test_collection\n\nSpecial Thanks\n==============\n\n- **Marc Abramowitz** (`@msabramo`_)\n- **Ryan Witt** (`@ryanwitt`_)\n\n.. _@msabramo: https://github.com/msabramo\n.. _@ryanwitt: https://github.com/ryanwitt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlosescri%2FDottedDict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarlosescri%2FDottedDict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlosescri%2FDottedDict/lists"}