Utils
Utils (atlas.utils) is the package containing general-purpose utility classes and helper functions for handling non-domain-specific operations that support
the overall infrastructure and application logic.
Below are the descriptions of each class.
StringFormatter
StringFormatter provides utility methods for converting strings between different formats. It is commonly used for transforming identifiers to match specific code style or naming requirements.
kebab_to_pascal(s)
staticmethod
Converts a given string from kebab-case to PascalCase format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
The kebab-case string to be converted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The converted string in |
pascal_to_kebab(string)
staticmethod
Converts a given string from PascalCase to kebab-case format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
The PascalCase string to be converted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The converted string in |
pascal_to_snake(string)
staticmethod
Converts a given string from PascalCase to snake_case format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
The PascalCase string to be converted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The converted string in |
snake_to_pascal(s)
staticmethod
Converts a given string from snake_case to PascalCase format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
The snake_case string to be converted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The converted string in |
to_snake_case(string)
staticmethod
Converts a given string to snake_case format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
The input string to be converted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The converted string in |
to_upper_snake_case(string)
staticmethod
Converts a given string to UPPER_SNAKE_CASE format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
The input string to be converted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The converted string in |
StackHelper
StackHelper provides utility methods to support stack and infrastructure management tasks within Atlas' CDK and local debugging structure. It includes helpers for detecting HTTP methods in endpoint directories, resolving route patterns, preparing AWS Lambda layers, parsing dependency definitions, and dynamically replacing environment variable placeholders in configuration data.
get_dependency_package_name(dependency)
staticmethod
Extracts the base package name from a dependency string, removing version constraints and URL references if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dependency
|
str
|
The dependency string (e.g., |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The normalized package name in lowercase. |
get_http_methods_by_endpoint_dir_path(dir_path)
staticmethod
Retrieves all available HTTP methods for a given endpoint directory based on existing
method handler files (e.g., GET.py, POST.py, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_path
|
str
|
The file system path of the endpoint directory to inspect. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of HTTP methods corresponding to the detected handler files. |
get_matching_dir_paths(glob_pattern, possible_base_paths)
staticmethod
Scans a set of base directories and returns all directory paths that match the given glob-like pattern.
Supports wildcard patterns (* for only the next segment and ** for any amount of next segments) for flexible matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
glob_pattern
|
str
|
A glob-like pattern representing the directory structure to match (e.g. |
required |
possible_base_paths
|
List[Path]
|
A list of base paths under which matching directories may be located. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of relative directory paths matching the given pattern, relative to their respective base paths. |
prepare_lambda_layers(root_path, lambda_layers_temp_dir_path, use_local=False, extras=None)
staticmethod
Prepares temporary directories for AWS Lambda layer packaging by copying internal project modules and installing dependencies into dedicated layer structures.
This process removes any previously existing temporary directories, replicates project code
under an internal/python/ directory, and installs dependencies under a libs/python/ directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_path
|
Path
|
The root directory of the project. |
required |
lambda_layers_temp_dir_path
|
Path
|
The temporary directory path for layer generation. |
required |
use_local
|
bool
|
Whether to use locally cached dependencies during installation. |
False
|
extras
|
str
|
An optional extras group (e.g., |
None
|
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If dependency installation fails. |
replace_env_var_placeholders(config, environment)
staticmethod
Recursively replaces env.VAR_NAME placeholders in configuration objects with their
corresponding environment variable values.
Supports nested data structures such as lists, dictionaries, and Pydantic models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
The configuration object (string, list, dict, or BaseModel) to process. |
required |
environment
|
Dict[str, str]
|
A dictionary containing the environment variables mapping. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
A new configuration object with placeholders replaced by actual environment values. |
resolve(*values)
staticmethod
Returns the first non-None value from the provided arguments, allowing explicit and predictable configuration overrides without implicit inheritance or deep merging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*values
|
A prioritized list of candidate values (read from left to right; from first to last parameter). |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The first non-None value, or None if all values are None. |