semvec/pypi-packages huggingface dataset:
cloudformation-loader 0.1.0
Import Python code embedded in CloudFormation Templates without hassle. Helps you test your Lambda Functions
Requires Python: >=3.10
Keywords: aws, lambda, test, cloudformation

# cloudformation-loader

Import Python code embedded in CloudFormation Templates without hassle

## Description

When you author Lambda Functions inside CloudFormation templates you often have the choice of inlining the 
code or maintaining the code externally.

Maintaining the Lambda code separate from the CloudFormation Template forces you to use a solution that packages and uploads the code for you (SAM, CDK, etc). It makes testing very easy, since we can import our Lambda code as any other Python file via imports, but it is often a hassle because you have to have utilities installed in your environment.

Inlining the code is very convenient because you don't have to worry about multiple files or external utilities, but it makes testing almost impossible (since the code is "locked" inside the CloudFormation Template). Until now.

## Usage

```
import cloudformation_loader
cloudformation_loader.import_from_cloudformation('mycloudformation.yaml', 'module_name', 'LambdaLogicalId')

import module_name

# call and use the code inside the Lambda Function
module_name.my_function('test')

# you can even call the handler
module_name.handler({ 'testing': 'me' })

# or use pytest
import pytest
assert module_name.my_function('test') == 42
```

## Contributions

Thanks to Yuriy Kurylyak for ideas and feedback.

The CloudFormation YAML loading code was taken from https://github.com/awslabs/aws-cfn-template-flip

Contributions are more than welcome.

The source code is located here: https://github.com/pplu/cloudformation-loader

Issuses can be opened here: https://github.com/pplu/cloudformation-loader/issues

## Author

Jose Luis Martinez Torres (pplusdomain@gmail.com)

## Copyright and License

Copyright (c) 2025 by Jose Luis Martinez Torres

This project is Apache-2.0
tree-traversals 0.1.0a0
Efficient and generic traversals for any Python tree structure with full ancestor paths.
Requires Python: >=2

# tree-traversals

_Efficient and generic traversals for any Python tree structure with full ancestor paths._

## Installation

```bash
pip install tree-traversals
```

## Supported Traversal Functions

| Traversal Function | Order                             | Yields                              |
|--------------------|-----------------------------------|-------------------------------------|
| `pre_order_dfs`    | Node, then children (depth-first) | (`ancestry`, `node`) in preorder    |
| `post_order_dfs`   | Children, then node (depth-first) | (`ancestry`, `node`) in postorder   |
| `layer_order_bfs`  | By tree level (breadth-first)     | (`ancestry`, `node`) in layer order |

All traversals:

- Take a starting node and a function to get descendants,
- Return an immutable [`cowlist`](https://pypi.org/project/cowlist/) stack representing the full path from root to the
  current node, along with the current node itself.

## Usage

```python
# coding=utf-8
from __future__ import print_function
from typing import Dict, List
from tree_traversals import (
    pre_order_dfs,
    post_order_dfs,
    layer_order_bfs
)

# Consider a simple binary tree (as a dict)
# - A
#   - B
#     - D
#     - E
#   - C
#     - F
tree = {
    'A': ['B', 'C'],
    'B': ['D', 'E'],
    'C': ['F'],
    'D': [],
    'E': [],
    'F': []
}  # type: Dict[str, List[str]]


def get_children(n):
    # type: (str) -> List[str]
    return tree[n]


# Then, you can perform any traversal easily:
print("Preorder DFS:")
for path, node in pre_order_dfs('A', get_children):
    print(repr(path), '->', repr(node))
# Preorder DFS:
# COWList([]) -> 'A'
# COWList(['A']) -> 'B'
# COWList(['A', 'B']) -> 'D'
# COWList(['A', 'B']) -> 'E'
# COWList(['A']) -> 'C'
# COWList(['A', 'C']) -> 'F'

print("\nPostorder DFS:")
for path, node in post_order_dfs('A', get_children):
    print(repr(path), '->', repr(node))
# Postorder DFS:
# COWList(['A', 'B']) -> 'D'
# COWList(['A', 'B']) -> 'E'
# COWList(['A']) -> 'B'
# COWList(['A', 'C']) -> 'F'
# COWList(['A']) -> 'C'
# COWList([]) -> 'A

print("\nLayer Order BFS:")
for path, node in layer_order_bfs('A', get_children):
    print(repr(path), '->', repr(node))
# Layer Order BFS
# COWList([]) -> 'A'
# COWList(['A']) -> 'B'
# COWList(['A']) -> 'C'
# COWList(['A', 'B']) -> 'D'
# COWList(['A', 'B']) -> 'E'
# COWList(['A', 'C']) -> 'F'
```

## Motivation

When working with trees, structure is easy - but traversal patterns are often rewritten, customized, and bug-prone.
`tree-traversals` lets you:

- Traverse any tree with a single function and a child-getter.
- Access the *full ancestor path* at every node.
- Clean up and de-duplicate your recursive tree code.
- Support any tree-shaped data—dicts, lists, ASTs, DOMs, file trees, you name it.

## Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

## License

This project is licensed under the [MIT License](LICENSE).