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 |
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_candidate_routes(glob_pattern, possible_base_paths)
staticmethod
Scans a set of base paths to find route directories matching a given glob 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
|
The pattern to match route directories against. |
required |
possible_base_paths
|
List[Path]
|
A list of base paths where routes may be located. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of candidate route paths relative to their base directories. |
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. |
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. |