Package: lxdx
lxdxis an “extended” Pythondictwith attribute-like accessibility.
Other than the usualdictoperations, functions and methods,
some useful functions are incorporated as well.Only supports Python 3.9+, due to the usage of theunion operatorfordict.Why this project?Hobbies and curiosities. Just for the fun of programming.dataclassis not cut for modelling hierarchical data.Brackets when accessing multi-layer data is too many.Dot notationmay be a cleaner way.Introduce utility functions likeget_from(path), inspired fromJsonPath, for programmability.Ability to add metadata to the items.Installationlxdxis available inPyPI, and installable viapip:pip install lxdxExamplesfromlxdximportDixtassertDixt()=={}assertDixt({1:1,'alpha':'α'})=={1:1,'alpha':'α'}assertDixt(alpha='α',beta='β')=={'alpha':'α','beta':'β'}assertDixt(alpha='α',beta='β').is_supermap_of({'beta':'β'})# data can be deeply nesteddata={'Accept-Encoding':'gzip','metadata':{'Content-Type':'application/json'}}dx=Dixt(**data)# update dx using the union operatordx|={'other':'dict or Dixt obj'}# 'Normalise' the keys to use it as attributes additionally.assertdx['Accept-Encoding']==dx.accept_encodingdeldx.accept_encodingprint(dx.metadata.CONTENT_TYPE)# Instead ofdx['a-list'][1]['obj-attr']='value'# Is way cleanerdx.a_list[1].obj_attr='value'# Programmatically get valuesassertdx.a_list[1].obj_attr==dx.get_from('$.a_list[1].obj_attr')json_str='{"a": "JSON string"}'assertDixt.from_json(json_str).json()==json_strDocumentationFull documentation is athttps://hardistones.github.io/lxdx.Futurelxdxis supposed to be a library of “extended”listanddict. For now there’s no use case for thelistextension.To be supportedUser-defined meta specification.LicenseThis 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:Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.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.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.