dpath


Namedpath JSON
Version 2.1.6 PyPI version JSON
download
home_pagehttps://github.com/dpath-maintainers/dpath-python
SummaryFilesystem-like pathing and searching for dictionaries
upload_time2023-05-21 21:35:33
maintainer
docs_urlNone
authorCaleb Case, Andrew Kesterson
requires_python>=3.7
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            dpath-python
============

|PyPI|
|Python Version|
|Build Status|
|Gitter|

A python library for accessing and searching dictionaries via
/slashed/paths ala xpath

Basically it lets you glob over a dictionary as if it were a filesystem.
It allows you to specify globs (ala the bash eglob syntax, through some
advanced fnmatch.fnmatch magic) to access dictionary elements, and
provides some facility for filtering those results.

sdists are available on pypi: http://pypi.python.org/pypi/dpath

Installing
==========

The best way to install dpath is via easy\_install or pip.

::

    easy_install dpath
    pip install dpath

Using Dpath
===========

.. code-block:: python

    import dpath

Separators
==========

All of the functions in this library (except 'merge') accept a
'separator' argument, which is the character that should separate path
components. The default is '/', but you can set it to whatever you want.

Searching
=========

Suppose we have a dictionary like this:

.. code-block:: python

    x = {
        "a": {
            "b": {
                "3": 2,
                "43": 30,
                "c": [],
                "d": ['red', 'buggy', 'bumpers'],
            }
        }
    }

... And we want to ask a simple question, like "Get me the value of the
key '43' in the 'b' hash which is in the 'a' hash". That's easy.

.. code-block:: pycon

    >>> help(dpath.get)
    Help on function get in module dpath:

    get(obj, glob, separator='/')
        Given an object which contains only one possible match for the given glob,
        return the value for the leaf matching the given glob.

        If more than one leaf matches the glob, ValueError is raised. If the glob is
        not found, KeyError is raised.

    >>> dpath.get(x, '/a/b/43')
    30

Or you could say "Give me a new dictionary with the values of all
elements in ``x['a']['b']`` where the key is equal to the glob ``'[cd]'``. Okay.

.. code-block:: pycon

    >>> help(dpath.search)
    Help on function search in module dpath:

    search(obj, glob, yielded=False)
    Given a path glob, return a dictionary containing all keys
    that matched the given glob.

    If 'yielded' is true, then a dictionary will not be returned.
    Instead tuples will be yielded in the form of (path, value) for
    every element in the document that matched the glob.

... Sounds easy!

.. code-block:: pycon

    >>> result = dpath.search(x, "a/b/[cd]")
    >>> print(json.dumps(result, indent=4, sort_keys=True))
    {
        "a": {
            "b": {
                "c": [],
                "d": [
                    "red",
                    "buggy",
                    "bumpers"
                ]
            }
        }
    }

... Wow that was easy. What if I want to iterate over the results, and
not get a merged view?

.. code-block:: pycon

    >>> for x in dpath.search(x, "a/b/[cd]", yielded=True): print(x)
    ...
    ('a/b/c', [])
    ('a/b/d', ['red', 'buggy', 'bumpers'])

... Or what if I want to just get all the values back for the glob? I
don't care about the paths they were found at:

.. code-block:: pycon

    >>> help(dpath.values)
    Help on function values in module dpath:

    values(obj, glob, separator='/', afilter=None, dirs=True)
    Given an object and a path glob, return an array of all values which match
    the glob. The arguments to this function are identical to those of search(),
    and it is primarily a shorthand for a list comprehension over a yielded
    search call.

    >>> dpath.values(x, '/a/b/d/*')
    ['red', 'buggy', 'bumpers']

Example: Setting existing keys
==============================

Let's use that same dictionary, and set keys like 'a/b/[cd]' to the
value 'Waffles'.

.. code-block:: pycon

    >>> help(dpath.set)
    Help on function set in module dpath:

    set(obj, glob, value)
    Given a path glob, set all existing elements in the document
    to the given value. Returns the number of elements changed.

    >>> dpath.set(x, 'a/b/[cd]', 'Waffles')
    2
    >>> print(json.dumps(x, indent=4, sort_keys=True))
    {
        "a": {
            "b": {
                "3": 2,
                "43": 30,
                "c": "Waffles",
                "d": "Waffles"
            }
        }
    }

Example: Adding new keys
========================

Let's make a new key with the path 'a/b/e/f/g', set it to "Roffle". This
behaves like 'mkdir -p' in that it makes all the intermediate paths
necessary to get to the terminus.

.. code-block:: pycon

    >>> help(dpath.new)
    Help on function new in module dpath:

    new(obj, path, value)
    Set the element at the terminus of path to value, and create
    it if it does not exist (as opposed to 'set' that can only
    change existing keys).

    path will NOT be treated like a glob. If it has globbing
    characters in it, they will become part of the resulting
    keys

    >>> dpath.new(x, 'a/b/e/f/g', "Roffle")
    >>> print(json.dumps(x, indent=4, sort_keys=True))
    {
        "a": {
            "b": {
                "3": 2,
                "43": 30,
                "c": "Waffles",
                "d": "Waffles",
                "e": {
                    "f": {
                        "g": "Roffle"
                    }
                }
            }
        }
    }

This works the way we expect with lists, as well. If you have a list
object and set index 10 of that list object, it will grow the list
object with None entries in order to make it big enough:

.. code-block:: pycon

    >>> dpath.new(x, 'a/b/e/f/h', [])
    >>> dpath.new(x, 'a/b/e/f/h/13', 'Wow this is a big array, it sure is lonely in here by myself')
    >>> print(json.dumps(x, indent=4, sort_keys=True))
    {
        "a": {
            "b": {
                "3": 2,
                "43": 30,
                "c": "Waffles",
                "d": "Waffles",
                "e": {
                    "f": {
                        "g": "Roffle",
                        "h": [
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            "Wow this is a big array, it sure is lonely in here by myself"
                        ]
                    }
                }
            }
        }
    }

Handy!

Example: Deleting Existing Keys
===============================

To delete keys in an object, use dpath.delete, which accepts the same globbing syntax as the other methods.

.. code-block:: pycon

    >>> help(dpath.delete)

    delete(obj, glob, separator='/', afilter=None):
        Given a path glob, delete all elements that match the glob.

        Returns the number of deleted objects. Raises PathNotFound if
        no paths are found to delete.

Example: Merging
================

Also, check out dpath.merge. The python dict update() method is
great and all but doesn't handle merging dictionaries deeply. This one
does.

.. code-block:: pycon

    >>> help(dpath.merge)
    Help on function merge in module dpath:

    merge(dst, src, afilter=None, flags=4, _path='')
        Merge source into destination. Like dict.update() but performs
        deep merging.

        flags is an OR'ed combination of MergeType enum members.
            * ADDITIVE : List objects are combined onto one long
              list (NOT a set). This is the default flag.
            * REPLACE : Instead of combining list objects, when
              2 list objects are at an equal depth of merge, replace
              the destination with the source.
            * TYPESAFE : When 2 keys at equal levels are of different
              types, raise a TypeError exception. By default, the source
              replaces the destination in this situation.

    >>> y = {'a': {'b': { 'e': {'f': {'h': [None, 0, 1, None, 13, 14]}}}, 'c': 'RoffleWaffles'}}
    >>> print(json.dumps(y, indent=4, sort_keys=True))
    {
        "a": {
            "b": {
                "e": {
                    "f": {
                        "h": [
                            null,
                            0,
                            1,
                            null,
                            13,
                            14
                        ]
                    }
                }
            },
            "c": "RoffleWaffles"
        }
    }
    >>> dpath.merge(x, y)
    >>> print(json.dumps(x, indent=4, sort_keys=True))
    {
        "a": {
            "b": {
                "3": 2,
                "43": 30,
                "c": "Waffles",
                "d": "Waffles",
                "e": {
                    "f": {
                        "g": "Roffle",
                        "h": [
                            null,
                            0,
                            1,
                            null,
                            13,
                            14,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            "Wow this is a big array, it sure is lonely in here by myself"
                        ]
                    }
                }
            },
            "c": "RoffleWaffles"
        }
    }

Now that's handy. You shouldn't try to use this as a replacement for the
deepcopy method, however - while merge does create new dict and list
objects inside the target, the terminus objects (strings and ints) are
not copied, they are just re-referenced in the merged object.

Filtering
=========

All of the methods in this library (except new()) support a 'afilter'
argument. This can be set to a function that will return True or False
to say 'yes include that value in my result set' or 'no don't include
it'.

Filtering functions receive every terminus node in a search - e.g.,
anything that is not a dict or a list, at the very end of the path. For
each value, they return True to include that value in the result set, or
False to exclude it.

Consider this example. Given the source dictionary, we want to find ALL
keys inside it, but we only really want the ones that contain "ffle" in
them:

.. code-block:: pycon

    >>> print(json.dumps(x, indent=4, sort_keys=True))
    {
        "a": {
            "b": {
                "3": 2,
                "43": 30,
                "c": "Waffles",
                "d": "Waffles",
                "e": {
                    "f": {
                        "g": "Roffle"
                    }
                }
            }
        }
    }
    >>> def afilter(x):
    ...     if "ffle" in str(x):
    ...             return True
    ...     return False
    ...
    >>> result = dpath.search(x, '**', afilter=afilter)
    >>> print(json.dumps(result, indent=4, sort_keys=True))
    {
        "a": {
            "b": {
                "c": "Waffles",
                "d": "Waffles",
                "e": {
                    "f": {
                      "g": "Roffle"
                    }
                }
            }
        }
    }

Obviously filtering functions can perform more advanced tests (regular
expressions, etc etc).

Key Names
=========

By default, dpath only understands dictionary keys that are integers or
strings. String keys must be non-empty. You can change this behavior by
setting a library-wide dpath option:

.. code-block:: python

    import dpath.options
    dpath.options.ALLOW_EMPTY_STRING_KEYS = True

Again, by default, this behavior is OFF, and empty string keys will
result in ``dpath.exceptions.InvalidKeyName`` being thrown.

Separator got you down? Use lists as paths
==========================================

The default behavior in dpath is to assume that the path given is a string, which must be tokenized by splitting at the separator to yield a distinct set of path components against which dictionary keys can be individually glob tested. However, this presents a problem when you want to use paths that have a separator in their name; the tokenizer cannot properly understand what you mean by '/a/b/c' if it is possible for '/' to exist as a valid character in a key name.

To get around this, you can sidestep the whole "filesystem path" style, and abandon the separator entirely, by using lists as paths. All of the methods in dpath.* support the use of a list instead of a string as a path. So for example:

.. code-block:: python

   >>> x = { 'a': {'b/c': 0}}
   >>> dpath.get(['a', 'b/c'])
   0

dpath.segments : The Low-Level Backend
======================================

dpath is where you want to spend your time: this library has the friendly
functions that will understand simple string globs, afilter functions, etc.

dpath.segments is the backend pathing library. It passes around tuples of path
components instead of string globs.

.. |PyPI| image:: https://img.shields.io/pypi/v/dpath.svg?style=flat
    :target: https://pypi.python.org/pypi/dpath/
    :alt: PyPI: Latest Version

.. |Python Version| image:: https://img.shields.io/pypi/pyversions/dpath?style=flat
    :target: https://pypi.python.org/pypi/dpath/
    :alt: Supported Python Version

.. |Build Status| image:: https://github.com/dpath-maintainers/dpath-python/actions/workflows/tests.yml/badge.svg
    :target: https://github.com/dpath-maintainers/dpath-python/actions/workflows/tests.yml
   
.. |Gitter| image:: https://badges.gitter.im/dpath-python/chat.svg
    :target: https://gitter.im/dpath-python/chat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
    :alt: Gitter

Contributors
============

We would like to thank the community for their interest and involvement. You
have all made this project significantly better than the sum of its parts, and
your continued feedback makes it better every day. Thank you so much!

The following authors have contributed to this project, in varying capacities:

+ Caleb Case <calebcase@gmail.com>
+ Andrew Kesterson <andrew@aklabs.net>
+ Marc Abramowitz <marc@marc-abramowitz.com>
+ Richard Han <xhh2a@berkeley.edu>
+ Stanislav Ochotnicky <sochotnicky@redhat.com>
+ Misja Hoebe <misja@conversify.com>
+ Gagandeep Singh <gagandeep.2020@gmail.com>
+ Alan Gibson <alan.gibson@gmail.com>

And many others! If we've missed you please open an PR and add your name here.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dpath-maintainers/dpath-python",
    "name": "dpath",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Caleb Case, Andrew Kesterson",
    "author_email": "calebcase@gmail.com, andrew@aklabs.net",
    "download_url": "https://files.pythonhosted.org/packages/0a/81/044f03129b6006fc594654bb26c22a9417346037261c767ac6e0773ca1dd/dpath-2.1.6.tar.gz",
    "platform": null,
    "description": "dpath-python\n============\n\n|PyPI|\n|Python Version|\n|Build Status|\n|Gitter|\n\nA python library for accessing and searching dictionaries via\n/slashed/paths ala xpath\n\nBasically it lets you glob over a dictionary as if it were a filesystem.\nIt allows you to specify globs (ala the bash eglob syntax, through some\nadvanced fnmatch.fnmatch magic) to access dictionary elements, and\nprovides some facility for filtering those results.\n\nsdists are available on pypi: http://pypi.python.org/pypi/dpath\n\nInstalling\n==========\n\nThe best way to install dpath is via easy\\_install or pip.\n\n::\n\n    easy_install dpath\n    pip install dpath\n\nUsing Dpath\n===========\n\n.. code-block:: python\n\n    import dpath\n\nSeparators\n==========\n\nAll of the functions in this library (except 'merge') accept a\n'separator' argument, which is the character that should separate path\ncomponents. The default is '/', but you can set it to whatever you want.\n\nSearching\n=========\n\nSuppose we have a dictionary like this:\n\n.. code-block:: python\n\n    x = {\n        \"a\": {\n            \"b\": {\n                \"3\": 2,\n                \"43\": 30,\n                \"c\": [],\n                \"d\": ['red', 'buggy', 'bumpers'],\n            }\n        }\n    }\n\n... And we want to ask a simple question, like \"Get me the value of the\nkey '43' in the 'b' hash which is in the 'a' hash\". That's easy.\n\n.. code-block:: pycon\n\n    >>> help(dpath.get)\n    Help on function get in module dpath:\n\n    get(obj, glob, separator='/')\n        Given an object which contains only one possible match for the given glob,\n        return the value for the leaf matching the given glob.\n\n        If more than one leaf matches the glob, ValueError is raised. If the glob is\n        not found, KeyError is raised.\n\n    >>> dpath.get(x, '/a/b/43')\n    30\n\nOr you could say \"Give me a new dictionary with the values of all\nelements in ``x['a']['b']`` where the key is equal to the glob ``'[cd]'``. Okay.\n\n.. code-block:: pycon\n\n    >>> help(dpath.search)\n    Help on function search in module dpath:\n\n    search(obj, glob, yielded=False)\n    Given a path glob, return a dictionary containing all keys\n    that matched the given glob.\n\n    If 'yielded' is true, then a dictionary will not be returned.\n    Instead tuples will be yielded in the form of (path, value) for\n    every element in the document that matched the glob.\n\n... Sounds easy!\n\n.. code-block:: pycon\n\n    >>> result = dpath.search(x, \"a/b/[cd]\")\n    >>> print(json.dumps(result, indent=4, sort_keys=True))\n    {\n        \"a\": {\n            \"b\": {\n                \"c\": [],\n                \"d\": [\n                    \"red\",\n                    \"buggy\",\n                    \"bumpers\"\n                ]\n            }\n        }\n    }\n\n... Wow that was easy. What if I want to iterate over the results, and\nnot get a merged view?\n\n.. code-block:: pycon\n\n    >>> for x in dpath.search(x, \"a/b/[cd]\", yielded=True): print(x)\n    ...\n    ('a/b/c', [])\n    ('a/b/d', ['red', 'buggy', 'bumpers'])\n\n... Or what if I want to just get all the values back for the glob? I\ndon't care about the paths they were found at:\n\n.. code-block:: pycon\n\n    >>> help(dpath.values)\n    Help on function values in module dpath:\n\n    values(obj, glob, separator='/', afilter=None, dirs=True)\n    Given an object and a path glob, return an array of all values which match\n    the glob. The arguments to this function are identical to those of search(),\n    and it is primarily a shorthand for a list comprehension over a yielded\n    search call.\n\n    >>> dpath.values(x, '/a/b/d/*')\n    ['red', 'buggy', 'bumpers']\n\nExample: Setting existing keys\n==============================\n\nLet's use that same dictionary, and set keys like 'a/b/[cd]' to the\nvalue 'Waffles'.\n\n.. code-block:: pycon\n\n    >>> help(dpath.set)\n    Help on function set in module dpath:\n\n    set(obj, glob, value)\n    Given a path glob, set all existing elements in the document\n    to the given value. Returns the number of elements changed.\n\n    >>> dpath.set(x, 'a/b/[cd]', 'Waffles')\n    2\n    >>> print(json.dumps(x, indent=4, sort_keys=True))\n    {\n        \"a\": {\n            \"b\": {\n                \"3\": 2,\n                \"43\": 30,\n                \"c\": \"Waffles\",\n                \"d\": \"Waffles\"\n            }\n        }\n    }\n\nExample: Adding new keys\n========================\n\nLet's make a new key with the path 'a/b/e/f/g', set it to \"Roffle\". This\nbehaves like 'mkdir -p' in that it makes all the intermediate paths\nnecessary to get to the terminus.\n\n.. code-block:: pycon\n\n    >>> help(dpath.new)\n    Help on function new in module dpath:\n\n    new(obj, path, value)\n    Set the element at the terminus of path to value, and create\n    it if it does not exist (as opposed to 'set' that can only\n    change existing keys).\n\n    path will NOT be treated like a glob. If it has globbing\n    characters in it, they will become part of the resulting\n    keys\n\n    >>> dpath.new(x, 'a/b/e/f/g', \"Roffle\")\n    >>> print(json.dumps(x, indent=4, sort_keys=True))\n    {\n        \"a\": {\n            \"b\": {\n                \"3\": 2,\n                \"43\": 30,\n                \"c\": \"Waffles\",\n                \"d\": \"Waffles\",\n                \"e\": {\n                    \"f\": {\n                        \"g\": \"Roffle\"\n                    }\n                }\n            }\n        }\n    }\n\nThis works the way we expect with lists, as well. If you have a list\nobject and set index 10 of that list object, it will grow the list\nobject with None entries in order to make it big enough:\n\n.. code-block:: pycon\n\n    >>> dpath.new(x, 'a/b/e/f/h', [])\n    >>> dpath.new(x, 'a/b/e/f/h/13', 'Wow this is a big array, it sure is lonely in here by myself')\n    >>> print(json.dumps(x, indent=4, sort_keys=True))\n    {\n        \"a\": {\n            \"b\": {\n                \"3\": 2,\n                \"43\": 30,\n                \"c\": \"Waffles\",\n                \"d\": \"Waffles\",\n                \"e\": {\n                    \"f\": {\n                        \"g\": \"Roffle\",\n                        \"h\": [\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            \"Wow this is a big array, it sure is lonely in here by myself\"\n                        ]\n                    }\n                }\n            }\n        }\n    }\n\nHandy!\n\nExample: Deleting Existing Keys\n===============================\n\nTo delete keys in an object, use dpath.delete, which accepts the same globbing syntax as the other methods.\n\n.. code-block:: pycon\n\n    >>> help(dpath.delete)\n\n    delete(obj, glob, separator='/', afilter=None):\n        Given a path glob, delete all elements that match the glob.\n\n        Returns the number of deleted objects. Raises PathNotFound if\n        no paths are found to delete.\n\nExample: Merging\n================\n\nAlso, check out dpath.merge. The python dict update() method is\ngreat and all but doesn't handle merging dictionaries deeply. This one\ndoes.\n\n.. code-block:: pycon\n\n    >>> help(dpath.merge)\n    Help on function merge in module dpath:\n\n    merge(dst, src, afilter=None, flags=4, _path='')\n        Merge source into destination. Like dict.update() but performs\n        deep merging.\n\n        flags is an OR'ed combination of MergeType enum members.\n            * ADDITIVE : List objects are combined onto one long\n              list (NOT a set). This is the default flag.\n            * REPLACE : Instead of combining list objects, when\n              2 list objects are at an equal depth of merge, replace\n              the destination with the source.\n            * TYPESAFE : When 2 keys at equal levels are of different\n              types, raise a TypeError exception. By default, the source\n              replaces the destination in this situation.\n\n    >>> y = {'a': {'b': { 'e': {'f': {'h': [None, 0, 1, None, 13, 14]}}}, 'c': 'RoffleWaffles'}}\n    >>> print(json.dumps(y, indent=4, sort_keys=True))\n    {\n        \"a\": {\n            \"b\": {\n                \"e\": {\n                    \"f\": {\n                        \"h\": [\n                            null,\n                            0,\n                            1,\n                            null,\n                            13,\n                            14\n                        ]\n                    }\n                }\n            },\n            \"c\": \"RoffleWaffles\"\n        }\n    }\n    >>> dpath.merge(x, y)\n    >>> print(json.dumps(x, indent=4, sort_keys=True))\n    {\n        \"a\": {\n            \"b\": {\n                \"3\": 2,\n                \"43\": 30,\n                \"c\": \"Waffles\",\n                \"d\": \"Waffles\",\n                \"e\": {\n                    \"f\": {\n                        \"g\": \"Roffle\",\n                        \"h\": [\n                            null,\n                            0,\n                            1,\n                            null,\n                            13,\n                            14,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            null,\n                            \"Wow this is a big array, it sure is lonely in here by myself\"\n                        ]\n                    }\n                }\n            },\n            \"c\": \"RoffleWaffles\"\n        }\n    }\n\nNow that's handy. You shouldn't try to use this as a replacement for the\ndeepcopy method, however - while merge does create new dict and list\nobjects inside the target, the terminus objects (strings and ints) are\nnot copied, they are just re-referenced in the merged object.\n\nFiltering\n=========\n\nAll of the methods in this library (except new()) support a 'afilter'\nargument. This can be set to a function that will return True or False\nto say 'yes include that value in my result set' or 'no don't include\nit'.\n\nFiltering functions receive every terminus node in a search - e.g.,\nanything that is not a dict or a list, at the very end of the path. For\neach value, they return True to include that value in the result set, or\nFalse to exclude it.\n\nConsider this example. Given the source dictionary, we want to find ALL\nkeys inside it, but we only really want the ones that contain \"ffle\" in\nthem:\n\n.. code-block:: pycon\n\n    >>> print(json.dumps(x, indent=4, sort_keys=True))\n    {\n        \"a\": {\n            \"b\": {\n                \"3\": 2,\n                \"43\": 30,\n                \"c\": \"Waffles\",\n                \"d\": \"Waffles\",\n                \"e\": {\n                    \"f\": {\n                        \"g\": \"Roffle\"\n                    }\n                }\n            }\n        }\n    }\n    >>> def afilter(x):\n    ...     if \"ffle\" in str(x):\n    ...             return True\n    ...     return False\n    ...\n    >>> result = dpath.search(x, '**', afilter=afilter)\n    >>> print(json.dumps(result, indent=4, sort_keys=True))\n    {\n        \"a\": {\n            \"b\": {\n                \"c\": \"Waffles\",\n                \"d\": \"Waffles\",\n                \"e\": {\n                    \"f\": {\n                      \"g\": \"Roffle\"\n                    }\n                }\n            }\n        }\n    }\n\nObviously filtering functions can perform more advanced tests (regular\nexpressions, etc etc).\n\nKey Names\n=========\n\nBy default, dpath only understands dictionary keys that are integers or\nstrings. String keys must be non-empty. You can change this behavior by\nsetting a library-wide dpath option:\n\n.. code-block:: python\n\n    import dpath.options\n    dpath.options.ALLOW_EMPTY_STRING_KEYS = True\n\nAgain, by default, this behavior is OFF, and empty string keys will\nresult in ``dpath.exceptions.InvalidKeyName`` being thrown.\n\nSeparator got you down? Use lists as paths\n==========================================\n\nThe default behavior in dpath is to assume that the path given is a string, which must be tokenized by splitting at the separator to yield a distinct set of path components against which dictionary keys can be individually glob tested. However, this presents a problem when you want to use paths that have a separator in their name; the tokenizer cannot properly understand what you mean by '/a/b/c' if it is possible for '/' to exist as a valid character in a key name.\n\nTo get around this, you can sidestep the whole \"filesystem path\" style, and abandon the separator entirely, by using lists as paths. All of the methods in dpath.* support the use of a list instead of a string as a path. So for example:\n\n.. code-block:: python\n\n   >>> x = { 'a': {'b/c': 0}}\n   >>> dpath.get(['a', 'b/c'])\n   0\n\ndpath.segments : The Low-Level Backend\n======================================\n\ndpath is where you want to spend your time: this library has the friendly\nfunctions that will understand simple string globs, afilter functions, etc.\n\ndpath.segments is the backend pathing library. It passes around tuples of path\ncomponents instead of string globs.\n\n.. |PyPI| image:: https://img.shields.io/pypi/v/dpath.svg?style=flat\n    :target: https://pypi.python.org/pypi/dpath/\n    :alt: PyPI: Latest Version\n\n.. |Python Version| image:: https://img.shields.io/pypi/pyversions/dpath?style=flat\n    :target: https://pypi.python.org/pypi/dpath/\n    :alt: Supported Python Version\n\n.. |Build Status| image:: https://github.com/dpath-maintainers/dpath-python/actions/workflows/tests.yml/badge.svg\n    :target: https://github.com/dpath-maintainers/dpath-python/actions/workflows/tests.yml\n   \n.. |Gitter| image:: https://badges.gitter.im/dpath-python/chat.svg\n    :target: https://gitter.im/dpath-python/chat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge\n    :alt: Gitter\n\nContributors\n============\n\nWe would like to thank the community for their interest and involvement. You\nhave all made this project significantly better than the sum of its parts, and\nyour continued feedback makes it better every day. Thank you so much!\n\nThe following authors have contributed to this project, in varying capacities:\n\n+ Caleb Case <calebcase@gmail.com>\n+ Andrew Kesterson <andrew@aklabs.net>\n+ Marc Abramowitz <marc@marc-abramowitz.com>\n+ Richard Han <xhh2a@berkeley.edu>\n+ Stanislav Ochotnicky <sochotnicky@redhat.com>\n+ Misja Hoebe <misja@conversify.com>\n+ Gagandeep Singh <gagandeep.2020@gmail.com>\n+ Alan Gibson <alan.gibson@gmail.com>\n\nAnd many others! If we've missed you please open an PR and add your name here.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Filesystem-like pathing and searching for dictionaries",
    "version": "2.1.6",
    "project_urls": {
        "Homepage": "https://github.com/dpath-maintainers/dpath-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "84c810c2d41a0958b76e777c07a521d64c871ab9022520babb3e08fa7eeb0810",
                "md5": "93785d022a124f9baee07da00117d675",
                "sha256": "31407395b177ab63ef72e2f6ae268c15e938f2990a8ecf6510f5686c02b6db73"
            },
            "downloads": -1,
            "filename": "dpath-2.1.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "93785d022a124f9baee07da00117d675",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 17474,
            "upload_time": "2023-05-21T21:35:31",
            "upload_time_iso_8601": "2023-05-21T21:35:31.873542Z",
            "url": "https://files.pythonhosted.org/packages/84/c8/10c2d41a0958b76e777c07a521d64c871ab9022520babb3e08fa7eeb0810/dpath-2.1.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0a81044f03129b6006fc594654bb26c22a9417346037261c767ac6e0773ca1dd",
                "md5": "84a4b13ad4fa0d98dfb5dcd0a7d538cc",
                "sha256": "f1e07c72e8605c6a9e80b64bc8f42714de08a789c7de417e49c3f87a19692e47"
            },
            "downloads": -1,
            "filename": "dpath-2.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "84a4b13ad4fa0d98dfb5dcd0a7d538cc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 28142,
            "upload_time": "2023-05-21T21:35:33",
            "upload_time_iso_8601": "2023-05-21T21:35:33.753220Z",
            "url": "https://files.pythonhosted.org/packages/0a/81/044f03129b6006fc594654bb26c22a9417346037261c767ac6e0773ca1dd/dpath-2.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-21 21:35:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dpath-maintainers",
    "github_project": "dpath-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "dpath"
}
        
Elapsed time: 0.07114s