Skip to main content
======
dotted
======

A Python library that provides a method of accessing lists and dicts with a
dotted path notation. It is useful to access a deep path inside a complex
object composed of lists and dicts.

Quick & Dirty:
==============

from dotted.collection import DottedCollection, DottedDict, DottedList

obj = DottedCollection.factory(dict_or_list)
obj = DottedCollection.load_json(json_value)
obj = DottedDict(a_dict)
obj = DottedList(a_list)

from dotted.utils import dot, dot_json

obj = dot(dict_or_list)
obj = dot_json(json_value)

``DottedDict`` and ``DottedList`` have the same accessors as ``dict`` and ``list``
so you can iterate them as usual. Both type of objects support access via a
dotted path key.

Examples
========

Example #1: DottedList
----------------------

obj = DottedList([0, 1, 2, 3, [4, 5, 6], 7, 8, [9, 10]])

All of these are true:

obj[0] == 0
obj['1'] == 1
obj['4.0'] == 4
obj['4.2'] == 6
obj[5] == 7
obj['7.1'] == 10

If you want to append you can do:

obj.append(12)

or:

obj[8] = 11

but the latter only works if ``index == len(obj)``. In other case you will get a
very pretty exception.

Example #2: DottedDict
----------------------

obj = DottedDict({'hello': {'world': {'wide': 'web'}}})

All of these are true:

obj['hello'] == {'world': {'wide': 'web'}}
obj['hello.world'] == {'wide': 'web'}
obj['hello.world.wide'] == 'web'

obj.hello == {'world': {'wide': 'web'}}
obj.hello.world == {'wide': 'web'}
obj.hello.world.wide == 'web'

Example #3: Both working together
---------------------------------

obj = DottedCollection.factory({
'hello': [{'world': {'wide': ['web', 'web', 'web']}}]
})

You can access:

obj['hello'][0]['world']['wide'][0]
obj.hello[0].world.wide[0]
obj.hello[0].world['wide'][0]
obj.hello[0].world['wide.0']
obj.hello['0.world'].wide[0]
...
obj['hello.0.world.wide.0']

Example #4: When new values are dicts or lists
----------------------------------------------

obj = DottedCollection.factory(some_obj)

obj['some.path'] = {'hello': 'world'} # will be converted to a DottedDict
obj['another.path'] = ['hello'] # will be converted to a DottedList

Example #5: Shortcuts
---------------------

from dotted.utils import dot, dot_json

obj = dot({'hello': 'world'})
obj = dot_json('{"hello": "world"}')

That's all!

## Tests

Run in the terminal from the parent directory:

python -m dotted.test.test_collection

Release files for dotted 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dotted 0.1.1
File Size Uploaded
dotted-0.1.1.tar.gz 6.8 kB Details

Release files / dotted-0.1.1.tar.gz

Download URL dotted-0.1.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
76c8c06bbf5bcfb5586ede417f3f79669e311526876415620494a9f6af747eba
BLAKE2b-256 checksum
How to use checksums
453c6a9d1b87d11c77573c0c1b7784e506fefd16e387e074cd24b493157387d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

This release

0.1.1 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page