gems
Python utilities for data manipulation and management.
Installation
Via github:
~$ git clone http://github.com/bprinty/gems.git
~$ cd gems
~$ python setup.py install
Via pip:
~$ pip install gems
Documentation
Documentation for the package can be found here.
Usage
The gems module provides specialized data structures to augment development. It’s similar to the collections module, but contains different types of objects.
Currently, the following objects are available (this list will grow with time and feedback):
Name |
Description |
|---|---|
composite |
JSON-like data structure for easy data traversal. |
filetree |
JSON-like data structure for easy filesystem traversal. |
composite
The composite object 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 the composite type in a project:
>>> from gems import composite
>>>
>>> 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] == 6
True
>>> data.two[0] == 1
True
In the example above, an arbitrary data structure is provided as an argument to the composite object, 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:
>>> from gems import composite
>>>
>>> with open('data.json', 'r') as fi:
>>> data = composite.load(fi)
>>>
>>> print data.four.five[1]
6
>>>
>>> with open('data.yml', 'r') as fi:
>>> data = composite.load(fi)
>>>
>>> print data.four.five[1]
6
There are also operations tied to composite objects. If two composite objects or a composite object and another similar type are added, you get a composite object as a result that combines the objects in an intuitive way:
>>> # using the 'data' object from above
>>> obj = data + {'five': 6}
>>> obj.five == 6
True
>>> obj.two === [1, 2, 3]
True
>>> obj = data + [1, 2, 3]
>>> obj[0].one.two[0] == 1
True
>>> obj[1][1] == 2
True
>>> data2 = composite([
1, 2, 3, {'four': 5}
])
>>> obj = data2 + {'five': 6}
>>> obj[0][0] == 1
True
>>> obj[0][2].four == 5
True
>>> obj = data2 + ['seven', 8, 9]
>>> obj[4:6] == ['seven', 8]
True
Other operations like this also can be used with the composite object. For example:
>>> # using the 'data' object from above
>>> 'three' in data
True
>>> 7 in data.four.five
True
>>> data.four.five == [6, 7, 8]
True
>>> data == data2
False
filetree
Traversal of a filetree is typically a pain in python. You could use os.path.walk to within a recursive function to accomplish it, but there should be an easier way. That’s where the gems.filetree comes in handy. Here is an example of how to use the gems.filetree type in a project:
>>> from gems import filetree
>>>
>>> # mydir is a directory with the structure below
>>> ftree = filetree('mydir')
>>> print ftree
mydir/
one/
two.txt
three.json
two/
three/
four.txt
five six/
seven.txt
eight.config
The gems.filetree structure also allows for traversal of the file data like so:
>>> print data.one['two.txt']
/full/path/to/mydir/one/two.txt
>>>
>>> print data.two.three['four.txt']
/full/path/to/mydir/two/three/four.txt
>>>
>>> print data.two['five six']['eight.config']
/full/path/to/mydir/two/five six/eight.config
Using JSON-based access is much easier and cleaner than doing many os.path.join operations to create the full paths to objects on your filesystem.
Questions/Feedback
File an issue in the GitHub issue tracker.
Metadata
Release files for gems 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gems-0.4.0.tar.gz | 20.5 kB | Without provenance | Details for gems-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gems-0.4.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for gems-0.4.0-py2.py3-none-any.whl |
Total release size: 35.4 kB
Release files / gems-0.4.0.tar.gz
| Download URL | gems-0.4.0.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb6c25e49622d44057851c6cc2676245dd4bfa406e5db41f5351a44970884150
|
|
BLAKE2b-256 checksum How to use checksums |
6280b664c8fc69e4003b6c9cb44e6c9e9b0b9e49f5f15d4966a02a06d415a26a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2
|
Release files / gems-0.4.0-py2.py3-none-any.whl
| Download URL | gems-0.4.0-py2.py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
7d0a1565f6a68f19c09e5e764b3d29260d86354a8524aaa1384f0a2bd8131ba1
|
|
BLAKE2b-256 checksum How to use checksums |
d3be5a0761ed9deb4d30a079bd022f4289d309075188cd2a7f17064e45f2de3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2
|
Security for gems 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.