Package: gems
gemsPython utilities for data manipulation and management.InstallationVia github:~$gitclonehttp://github.com/bprinty/gems.git~$cdgems~$pythonsetup.pyinstallVia pip:~$pipinstallgemsDocumentationDocumentation for the package can be foundhere.UsageThegemsmodule provides specialized data structures to augment development. It’s similar to thecollectionsmodule, but contains different types of objects.Currently, the following objects are available (this list will grow with time and feedback):NameDescriptioncompositeJSON-like data structure for easy data traversal.filetreeJSON-like data structure for easy filesystem traversal.compositeThecompositeobject abstracts away the complexity associated with managing heavily nested JSON-based structures, allowing easier access to internal properties, and providing operators that work with the data in an intuitive way. Here is a simple example of how to use thecompositetype in a project:>>>fromgemsimportcomposite>>>>>>data=composite({>>>'one':1,>>>'two':[1,2,3],>>>'three':['one',2,{'three':'four'}],>>>'four':{'five':[6,7,8],'nine':10,'eleven':'twelve'}>>>})>>>data.four.five[1]==6True>>>data.two[0]==1TrueIn the example above, an arbitrary data structure is provided as an argument to thecompositeobject, and is transformed into an object where properties can be traversed more gracefully (syntactically). You can also load a composite object from a json or yaml file like so:>>>fromgemsimportcomposite>>>>>>withopen('data.json','r')asfi:>>>data=composite.load(fi)>>>>>>printdata.four.five[1]6>>>>>>withopen('data.yml','r')asfi:>>>data=composite.load(fi)>>>>>>printdata.four.five[1]6There are also operations tied tocompositeobjects. If two composite objects or a composite object and another similar type are added, you get acompositeobject as a result that combines the objects in an intuitive way:>>># using the 'data' object from above>>>obj=data+{'five':6}>>>obj.five==6True>>>obj.two===[1,2,3]True>>>obj=data+[1,2,3]>>>obj[0].one.two[0]==1True>>>obj[1][1]==2True>>>data2=composite([1,2,3,{'four':5}])>>>obj=data2+{'five':6}>>>obj[0][0]==1True>>>obj[0][2].four==5True>>>obj=data2+['seven',8,9]>>>obj[4:6]==['seven',8]TrueOther operations like this also can be used with thecompositeobject. For example:>>># using the 'data' object from above>>>'three'indataTrue>>>7indata.four.fiveTrue>>>data.four.five==[6,7,8]True>>>data==data2FalsefiletreeTraversal of a filetree is typically a pain in python. You could useos.path.walkto within a recursive function to accomplish it, but there should be an easier way. That’s where thegems.filetreecomes in handy. Here is an example of how to use thegems.filetreetype in a project:>>>fromgemsimportfiletree>>>>>># mydir is a directory with the structure below>>>ftree=filetree('mydir')>>>printftreemydir/one/two.txtthree.jsontwo/three/four.txtfivesix/seven.txteight.configThegems.filetreestructure also allows for traversal of the file data like so:>>>printdata.one['two.txt']/full/path/to/mydir/one/two.txt>>>>>>printdata.two.three['four.txt']/full/path/to/mydir/two/three/four.txt>>>>>>printdata.two['five six']['eight.config']/full/path/to/mydir/two/fivesix/eight.configUsing JSON-based access is much easier and cleaner than doing manyos.path.joinoperations to create the full paths to objects on your filesystem.Questions/FeedbackFile an issue in theGitHub issue tracker.