Metadata-Version: 2.1
Name: softy
Version: 0.0.4
Summary: Python Softy
Project-URL: Homepage, https://github.com/jackmuskopf/softy
Project-URL: Bug Tracker, https://github.com/jackmuskopf/softy/issues
Author-email: Jack Muskopf <jam.muskopf@gmail.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Description-Content-Type: text/markdown

# Softy

[![license](https://img.shields.io/github/license/jackmuskopf/softy.svg)](https://github.com/jackmuskopf/softy/blob/main/LICENSE)

Soft access of nested data for more readable code
- Lightweight
- Pure Python
- One source file
- < 150 lines of code
- No dependencies


An item:
```python
basket = {
    "Fruits": [
        {
            "Type": "Apple",
            "Color": "Green"
        },
        {
            "Type": "Apple",
            "Color": "Red"
        }
    ],
    "Blanket": {
        "Material": "Cotton",
        "Color": "Red"
    }
}
```

Before:
```python
# get the blanket color
blanket = basket.get('Blanket')
blanket_color = None
if blanket:
    blanket_color = blanket.get('Color')
if blanket_color is not None:
    print(f'Blanket is {blanket_color}')
else:
    print('Unspecified blanket color')

# get the color of the third fruit
fruits = basket.get('Fruits')
fruit_color = None
if fruits is not None:
    if len(fruits) > 2:
        fruit_color = fruits[2].get('Color')
if fruit_color is not None:
    print(f'3rd fruit color is {fruit_color}')
else:
    print('Unspecified 3rd fruit color')
```


After:
```python
import softy
basket = softy.soften(basket)

# get the blanket color
if basket.Blanket.Color is not softy.null:
    print(f'Blanket is {basket.Blanket.Color}')
else:
    print('Unspecified blanket color')

# get the color of the third fruit
if basket.Fruits.i(2).Color is not softy.null:
    print(f'3rd fruit color is {fruit_color}')
else:
    print('Unspecified 3rd fruit color')

# built-in indexing still works the same
try:
    wine = basket['Wine']
except KeyError:
    print('Forgot the wine')
else:
    assert False
```