Python Softy
Project description
Softy
Soft access of nested data for more readable code
- Lightweight
- Pure Python
- One source file
- < 150 lines of code
- No dependencies
An item:
basket = {
"Fruits": [
{
"Type": "Apple",
"Color": "Green"
},
{
"Type": "Apple",
"Color": "Red"
}
],
"Blanket": {
"Material": "Cotton",
"Color": "Red"
}
}
Before:
# 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:
import softy
basket = softy.softy(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[3].Color is not softy.null:
print(f'3rd fruit color is {fruit_color}')
else:
print('Unspecified 3rd fruit color')
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
softy-0.0.1.tar.gz
(4.9 kB
view details)
Built Distribution
softy-0.0.1-py3-none-any.whl
(3.5 kB
view details)
File details
Details for the file softy-0.0.1.tar.gz
.
File metadata
- Download URL: softy-0.0.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d3848f39c642a8d8244d1d192201c71435746c471fd817232c5f7fc1d618932 |
|
MD5 | bccc511a58b230746cda58982511f0ce |
|
BLAKE2b-256 | f1795a74a847aafef36f523174b14e63e568e1d77413a6366c826731ea8da740 |
File details
Details for the file softy-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: softy-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 686c1f59b4b444bbf9ab1c631113a61f10fa0e65590e1def87bed75d44b251a7 |
|
MD5 | 50c56fff59618ec7edc3651b29002c99 |
|
BLAKE2b-256 | c9e04ba72f578dc2f1365224687a10ef55a65ff5af2ce02e4ebd86f8c4281eae |