A CLI tool that generates Python Enum classes from Serverless Framework configuration files. This tool parses your serverless.yml
file and creates type-safe Enum objects for Lambda function names, making it easier to reference your functions in Python code.
- Generate Python Enum classes from
serverless.yml
files - Support for stage-specific function naming
- Type-safe Lambda function name references
- Dry-run mode for previewing generated code
- Easy integration with existing Python projects
pip install sls_enum
Or using Poetry:
poetry add sls_enum
Generate an Enum class from your serverless.yml:
sls_enum serverless.yml output.py
Include stage in function names:
sls_enum serverless.yml output.py --stage dev
Preview the generated code without writing to file:
sls_enum serverless.yml output.py --dry-run
Given a serverless.yml
with functions like:
service: my-service
functions:
sample-handler:
handler: handler.sample
another-handler:
handler: handler.another
The tool generates:
from enum import Enum
class LambdaHandlers(str, Enum):
sample_handler = "my-service-sample-handler"
another_handler = "my-service-another-handler"
FP
: Path to serverless.yml file (required)OUTPUT
: Output Python file path (required)--stage TEXT
: Stage name to include in function names--dry-run
: Preview generated code without writing to file--help
: Show help message
poetry install
poetry run pytest
poetry run black .
poetry run isort .
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Run tests and ensure code formatting
- Create a pull request targeting the main branch
- Assign @hayata-yamamoto as a reviewer
See LICENSE file for details.