Skip to main content

Python Softy

Project description

Softy

license

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.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[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.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

softy-0.0.2-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file softy-0.0.2.tar.gz.

File metadata

  • Download URL: softy-0.0.2.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

Hashes for softy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 288687896f47b76db50b1254fb7ab71c660488009d0d32fd49185dee8780eee3
MD5 e462b48f270fe901d2c482daa7b0d272
BLAKE2b-256 912115cf9912018119b936d64ed1a48a84f882c7c0999f40953b095f22a0af0a

See more details on using hashes here.

File details

Details for the file softy-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: softy-0.0.2-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

Hashes for softy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bb0720f3e7ec9f46729d3ba4d11a560323c603a8f6d530dbd6125151c95dd8ec
MD5 e5dfe7163b3f89424b0f103efcf4adb5
BLAKE2b-256 ba317bc64b57aafea2a1d29364e3cf6d3ef3719d1de513a6bac66d2c07257efa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page