{"id":15573334,"url":"https://github.com/pirhoo/spytula","last_synced_at":"2026-04-13T01:17:24.037Z","repository":{"id":182777676,"uuid":"655831418","full_name":"pirhoo/spytula","owner":"pirhoo","description":"A Python library that provides a simple and convenient way to build JSON and YAML data structures using a builder pattern.","archived":false,"fork":false,"pushed_at":"2023-06-19T20:56:22.000Z","size":797,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-28T14:45:30.973Z","etag":null,"topics":["data","dsl","json","python","yaml"],"latest_commit_sha":null,"homepage":"https://pirhoo.github.io/spytula/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pirhoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-06-19T17:34:03.000Z","updated_at":"2023-07-24T07:32:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"99a02063-2e18-4967-9675-1f81dbbafba9","html_url":"https://github.com/pirhoo/spytula","commit_stats":null,"previous_names":["pirhoo/spytula"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirhoo%2Fspytula","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirhoo%2Fspytula/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirhoo%2Fspytula/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirhoo%2Fspytula/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pirhoo","download_url":"https://codeload.github.com/pirhoo/spytula/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246150419,"owners_count":20731419,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","dsl","json","python","yaml"],"created_at":"2024-10-02T18:11:56.388Z","updated_at":"2025-11-06T12:03:22.357Z","avatar_url":"https://github.com/pirhoo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 👩‍🍳 Spytula [![](https://img.shields.io/github/actions/workflow/status/pirhoo/spytula/main.yml)](https://github.com/pirhoo/spytula/actions)\n\nSpytula is a Python library that provides a simple and convenient way to build JSON and YAML data structures using a builder pattern.\n\n## Installation\n\nUse pip to install the Spytula library:\n\n```bash\npip install spytula\n```\n\n## Usage    \n\nImport the `SpytulaBuilder` class from the `spytula.builder` module:\n\n```python\nfrom spytula.builder import SpytulaBuilder\n\n# Create an instance of SpytulaBuilder\nbuilder = SpytulaBuilder()\n\n# Add attributes to the JSON structure\nbuilder.attribute('name', 'Ramen')\nbuilder.attribute('origin', 'Japan')\n\n# Create a list of ingredients\nfor builder.each('ingredients') as add_ingredient:    \n    for ingredient in ['Noodles', 'Pork', 'Eggs', 'Miso']:\n        with add_ingredient() as ingredient_builder:\n            ingredient_builder.attribute('name', ingredient)\n\n# Add optional attributes conditionally\nbuilder.when('spiciness', 'Medium', True)\nbuilder.when('extra_toppings', ['Green Onions', 'Nori', 'Bamboo Shoots'], True)\n\n# Configure the key to use camelcase\nbuilder.key_format(camelize={'uppercase_first_letter': False})\n\n# Convert the JSON structure to JSON-formatted string\njson_output = builder.to_json(indent=4)\n\n# Print the JSON output\nprint(json_output)\n```\n\nThis will output:\n\n```json\n{\n    \"name\": \"Ramen\",\n    \"origin\": \"Japan\",\n    \"ingredients\": [\n        { \"name\": \"Noodles\" },\n        { \"name\": \"Pork\" },\n        { \"name\": \"Eggs\" },\n        { \"name\": \"Miso\" }\n    ],\n    \"spiciness\": \"Medium\",\n    \"extraToppings\": [\n        \"Green Onions\",\n        \"Nori\",\n        \"Bamboo Shoots\"\n    ]\n}\n\n```\n\nIn 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.\n\n## Documentation    \n\nRefer for the [documentation](https://pirhoo.github.io/spytula/) for more details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirhoo%2Fspytula","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpirhoo%2Fspytula","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirhoo%2Fspytula/lists"}