flask_more_smorest.utils

Utility functions for Flask-Smorest CRUD operations.

This module provides common utility functions for password hashing and string case conversion.

Functions

check_password_hash(password, hashed)

Check if a password matches a bcrypt hash.

convert_camel_to_snake(word)

Convert CamelCase string to snake_case.

convert_snake_to_camel(word)

Convert snake_case string to CamelCase.

generate_password_hash(password)

Generate a secure bcrypt hash for a password.

flask_more_smorest.utils.generate_password_hash(password)[source]

Generate a secure bcrypt hash for a password.

Parameters:

password (str | bytes) – The password to hash (string or bytes)

Return type:

bytes

Returns:

The hashed password as bytes

Example

>>> hashed = generate_password_hash("my_secure_password")
>>> isinstance(hashed, bytes)
True
flask_more_smorest.utils.check_password_hash(password, hashed)[source]

Check if a password matches a bcrypt hash.

Parameters:
  • password (str | bytes | None) – The password to check (string or bytes)

  • hashed (bytes | str | None) – The hashed password to compare against (bytes or string)

Return type:

bool

Returns:

True if the password matches the hash, False otherwise

Example

>>> hashed = generate_password_hash("password123")
>>> check_password_hash("password123", hashed)
True
>>> check_password_hash("wrong", hashed)
False
flask_more_smorest.utils.convert_snake_to_camel(word)[source]

Convert snake_case string to CamelCase.

Parameters:

word (str) – Snake case string to convert

Return type:

str

Returns:

CamelCase version of the input string

Example

>>> convert_snake_to_camel("user_profile")
'UserProfile'
>>> convert_snake_to_camel("simple")
'simple'
flask_more_smorest.utils.convert_camel_to_snake(word)[source]

Convert CamelCase string to snake_case.

Parameters:

word (str) – CamelCase string to convert

Return type:

str

Returns:

snake_case version of the input string

Example

>>> convert_camel_to_snake("UserProfile")
'user_profile'
>>> convert_camel_to_snake("APIKey")
'api_key'