lxdx


Namelxdx JSON
Version 0.4.3 PyPI version JSON
download
home_pagehttps://github.com/hardistones/lxdx
SummaryJust an extended Python dict with attribute-accessibility, extra methods, and metadata
upload_time2023-06-22 03:31:06
maintainer
docs_urlNone
authorHardy Stones
requires_python>=3.9,<4.0
license3-Clause BSD License
keywords dict extended normalize metadata
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            lxdx
====

``lxdx`` is an "extended" Python ``dict`` with attribute-like accessibility.
Other than the usual ``dict`` operations, functions and methods,
some useful functions are incorporated as well.

Only supports Python 3.9+, due to the usage of the `union operator`_ for ``dict``.

Why this project?
-----------------
* Hobbies and curiosities. Just for the fun of programming.
* ``dataclass`` is not cut for modelling hierarchical data.
* Brackets when accessing multi-layer data is too many. `Dot notation`_ may be a cleaner way.
* Introduce utility functions like ``get_from(path)``, inspired from `JsonPath`_, for programmability.
* Ability to add metadata to the items.

Installation
------------
``lxdx`` is available in `PyPI <https://pypi.org/project/lxdx>`_, and installable via ``pip``:

.. code-block::

    pip install lxdx


Examples
--------
.. code-block:: python

    from lxdx import Dixt

    assert Dixt() == {}
    assert Dixt({1: 1, 'alpha': 'α'}) == {1: 1, 'alpha': 'α'}
    assert Dixt(alpha='α', beta='β') == {'alpha': 'α', 'beta': 'β'}
    assert Dixt(alpha='α', beta='β').is_supermap_of({'beta': 'β'})

    # data can be deeply nested
    data = {'Accept-Encoding': 'gzip', 'metadata': {'Content-Type': 'application/json'}}
    dx = Dixt(**data)

    # update dx using the union operator
    dx |= {'other': 'dict or Dixt obj'}

    # 'Normalise' the keys to use it as attributes additionally.
    assert dx['Accept-Encoding'] == dx.accept_encoding
    del dx.accept_encoding
    print(dx.metadata.CONTENT_TYPE)

    # Instead of
    dx['a-list'][1]['obj-attr'] = 'value'

    # Is way cleaner
    dx.a_list[1].obj_attr = 'value'

    # Programmatically get values
    assert dx.a_list[1].obj_attr == dx.get_from('$.a_list[1].obj_attr')

    json_str = '{"a": "JSON string"}'
    assert Dixt.from_json(json_str).json() == json_str

Documentation
-------------
Full documentation is at https://hardistones.github.io/lxdx.

Future
------
``lxdx`` is supposed to be a library of "extended" ``list`` and ``dict``. For now there's no use case for the ``list`` extension.

**To be supported**

- User-defined meta specification.

License
-------
This project and all its files are licensed under the 3-Clause BSD License.

    Copyright (c) 2021, @github.com/hardistones
    All rights reserved.

    Redistribution and use in source and binary forms, with or without modification,
    are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this
       list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.

    3. Neither the name of the copyright holder nor the names of its contributors
       may be used to endorse or promote products derived from this software without
       specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
    ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


.. References
.. _union operator: https://www.python.org/dev/peps/pep-0584
.. _dot notation: https://en.wikipedia.org/wiki/Property_(programming)#Dot_notation
.. _JsonPath: https://github.com/json-path/JsonPath


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hardistones/lxdx",
    "name": "lxdx",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "dict,extended,normalize,metadata",
    "author": "Hardy Stones",
    "author_email": "hardistones@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4c/b8/9417c38100d5a5b1d21ce1b11c2414449b6655aa6f9134be08fe67321efe/lxdx-0.4.3.tar.gz",
    "platform": null,
    "description": "lxdx\n====\n\n``lxdx`` is an \"extended\" Python ``dict`` with attribute-like accessibility.\nOther than the usual ``dict`` operations, functions and methods,\nsome useful functions are incorporated as well.\n\nOnly supports Python 3.9+, due to the usage of the `union operator`_ for ``dict``.\n\nWhy this project?\n-----------------\n* Hobbies and curiosities. Just for the fun of programming.\n* ``dataclass`` is not cut for modelling hierarchical data.\n* Brackets when accessing multi-layer data is too many. `Dot notation`_ may be a cleaner way.\n* Introduce utility functions like ``get_from(path)``, inspired from `JsonPath`_, for programmability.\n* Ability to add metadata to the items.\n\nInstallation\n------------\n``lxdx`` is available in `PyPI <https://pypi.org/project/lxdx>`_, and installable via ``pip``:\n\n.. code-block::\n\n    pip install lxdx\n\n\nExamples\n--------\n.. code-block:: python\n\n    from lxdx import Dixt\n\n    assert Dixt() == {}\n    assert Dixt({1: 1, 'alpha': '\u03b1'}) == {1: 1, 'alpha': '\u03b1'}\n    assert Dixt(alpha='\u03b1', beta='\u03b2') == {'alpha': '\u03b1', 'beta': '\u03b2'}\n    assert Dixt(alpha='\u03b1', beta='\u03b2').is_supermap_of({'beta': '\u03b2'})\n\n    # data can be deeply nested\n    data = {'Accept-Encoding': 'gzip', 'metadata': {'Content-Type': 'application/json'}}\n    dx = Dixt(**data)\n\n    # update dx using the union operator\n    dx |= {'other': 'dict or Dixt obj'}\n\n    # 'Normalise' the keys to use it as attributes additionally.\n    assert dx['Accept-Encoding'] == dx.accept_encoding\n    del dx.accept_encoding\n    print(dx.metadata.CONTENT_TYPE)\n\n    # Instead of\n    dx['a-list'][1]['obj-attr'] = 'value'\n\n    # Is way cleaner\n    dx.a_list[1].obj_attr = 'value'\n\n    # Programmatically get values\n    assert dx.a_list[1].obj_attr == dx.get_from('$.a_list[1].obj_attr')\n\n    json_str = '{\"a\": \"JSON string\"}'\n    assert Dixt.from_json(json_str).json() == json_str\n\nDocumentation\n-------------\nFull documentation is at https://hardistones.github.io/lxdx.\n\nFuture\n------\n``lxdx`` is supposed to be a library of \"extended\" ``list`` and ``dict``. For now there's no use case for the ``list`` extension.\n\n**To be supported**\n\n- User-defined meta specification.\n\nLicense\n-------\nThis project and all its files are licensed under the 3-Clause BSD License.\n\n    Copyright (c) 2021, @github.com/hardistones\n    All rights reserved.\n\n    Redistribution and use in source and binary forms, with or without modification,\n    are permitted provided that the following conditions are met:\n\n    1. Redistributions of source code must retain the above copyright notice, this\n       list of conditions and the following disclaimer.\n\n    2. Redistributions in binary form must reproduce the above copyright notice,\n       this list of conditions and the following disclaimer in the documentation\n       and/or other materials provided with the distribution.\n\n    3. Neither the name of the copyright holder nor the names of its contributors\n       may be used to endorse or promote products derived from this software without\n       specific prior written permission.\n\n    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\n    ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\n    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\n.. References\n.. _union operator: https://www.python.org/dev/peps/pep-0584\n.. _dot notation: https://en.wikipedia.org/wiki/Property_(programming)#Dot_notation\n.. _JsonPath: https://github.com/json-path/JsonPath\n\n",
    "bugtrack_url": null,
    "license": "3-Clause BSD License",
    "summary": "Just an extended Python dict with attribute-accessibility, extra methods, and metadata",
    "version": "0.4.3",
    "project_urls": {
        "Bug Tracker": "https://github.com/hardistones/lxdx/issues",
        "Documentation": "https://hardistones.github.io/lxdx",
        "Homepage": "https://github.com/hardistones/lxdx"
    },
    "split_keywords": [
        "dict",
        "extended",
        "normalize",
        "metadata"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "31a8fc3e6d8e88a69cb7628e9da69f733dc3f9a4eabffad49f2567c88d2c3866",
                "md5": "9e2b23ff91e89624171d5387b5b53950",
                "sha256": "49b44653c25fb9ba6951c9d0d24f20369fc943af37942ebc5d7efacd3b191023"
            },
            "downloads": -1,
            "filename": "lxdx-0.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9e2b23ff91e89624171d5387b5b53950",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 10603,
            "upload_time": "2023-06-22T03:31:04",
            "upload_time_iso_8601": "2023-06-22T03:31:04.865457Z",
            "url": "https://files.pythonhosted.org/packages/31/a8/fc3e6d8e88a69cb7628e9da69f733dc3f9a4eabffad49f2567c88d2c3866/lxdx-0.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4cb89417c38100d5a5b1d21ce1b11c2414449b6655aa6f9134be08fe67321efe",
                "md5": "bfd9a66029feb2cd862aa81a0fceab7e",
                "sha256": "fcdedf00ed6fd5bded4cc069efe822b73a0c32bdfa28a781c3021aee68312e50"
            },
            "downloads": -1,
            "filename": "lxdx-0.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "bfd9a66029feb2cd862aa81a0fceab7e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 9812,
            "upload_time": "2023-06-22T03:31:06",
            "upload_time_iso_8601": "2023-06-22T03:31:06.412365Z",
            "url": "https://files.pythonhosted.org/packages/4c/b8/9417c38100d5a5b1d21ce1b11c2414449b6655aa6f9134be08fe67321efe/lxdx-0.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-22 03:31:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hardistones",
    "github_project": "lxdx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "lxdx"
}
        
Elapsed time: 0.13456s