Skip to main content

👩‍🍳 Spytula

Spytula is a Python library that provides a simple and convenient way to build JSON and YAML data structures using a builder pattern.

Installation

Use pip to install the Spytula library:

pip install spytula

Usage

Import the SpytulaBuilder class from the spytula.builder module:

from spytula.builder import SpytulaBuilder

# Create an instance of SpytulaBuilder
builder = SpytulaBuilder()

# Add attributes to the JSON structure
builder.attribute('name', 'Ramen')
builder.attribute('origin', 'Japan')

# Create a list of ingredients
for builder.each('ingredients') as add_ingredient:    
    for ingredient in ['Noodles', 'Pork', 'Eggs', 'Miso']:
        with add_ingredient() as ingredient_builder:
            ingredient_builder.attribute('name', ingredient)

# Add optional attributes conditionally
builder.when('spiciness', 'Medium', True)
builder.when('extra_toppings', ['Green Onions', 'Nori', 'Bamboo Shoots'], True)

# Configure the key to use camelcase
builder.key_format(camelize={'uppercase_first_letter': False})

# Convert the JSON structure to JSON-formatted string
json_output = builder.to_json(indent=4)

# Print the JSON output
print(json_output)

This will output:

{
    "name": "Ramen",
    "origin": "Japan",
    "ingredients": [
        { "name": "Noodles" },
        { "name": "Pork" },
        { "name": "Eggs" },
        { "name": "Miso" }
    ],
    "spiciness": "Medium",
    "extraToppings": [
        "Green Onions",
        "Nori",
        "Bamboo Shoots"
    ]
}

In this example, we create a SpytulaBuilder instance and add attributes like name and origin to represent Ramen. We use the nodes() context manager to create a list of ingredients and add them to the JSON structure. Optional attributes like spiciness and toppings are added conditionally using the when() method. Finally, we convert the JSON structure to a JSON-formatted string using to_json() with an indentation of 4 spaces.

Documentation

Refer for the documentation for more details.

Metadata

Release files for spytula 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spytula 0.0.3
File Size Uploaded Provenance Actions
spytula-0.0.3.tar.gz 6.2 kB Without provenance Details for spytula-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spytula 0.0.3
File Interpreter ABI Platform Actions
spytula-0.0.3-py3-none-any.whl Python 3 none any Details for spytula-0.0.3-py3-none-any.whl

Total release size: 12.5 kB

Release files / spytula-0.0.3.tar.gz

Download URL spytula-0.0.3.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b2ae997a9f7b750779b8d7e2176621637cb2e71063b04adb34df8c5b2084d268
BLAKE2b-256 checksum
How to use checksums
43c5e98bfc4bb6384e0ebfcca32ab4f1ea1a861e4ce2b6875f1cc4f4f166cc8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-45-generic

Release files / spytula-0.0.3-py3-none-any.whl

Download URL spytula-0.0.3-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e00aa4df38e348f5b17c15d0265f73e200c739649be43154fa87e51fb9c0344
BLAKE2b-256 checksum
How to use checksums
d7e8599a0a449f761f5a2175599ebf5904c7eea4cf98b05b48d3f9b772e18925
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-45-generic

Security for spytula 0.0.3

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page