Utilities
The rick.util package provides small helper functions organized by topic.
cast
Type casting functions that return None on failure instead of raising exceptions.
Location: rick.util.cast
| Function | Returns | Description |
|---|---|---|
cast_str(value) |
str or None | Convert to string; None on failure |
cast_int(value) |
int or None | Convert to int; None on failure |
cast_float(value) |
float or None | Convert to float; None on failure |
datetime
Date/time utilities.
Location: rick.util.datetime
iso8601_now() -> str
Return the current date and time as an ISO 8601 string with timezone info.
loader
Dynamic class loading.
Location: rick.util.loader
load_class(path: str, raise_exception: bool = False) -> class or None
Load a class by its dotted module path.
cls = load_class('rick.resource.redis.RedisCache')
cache = cls(host='localhost')
# Raises ModuleNotFoundError if not found
cls = load_class('nonexistent.Module', raise_exception=True)
Parameters:
path(str) - Dotted path (e.g.'package.module.ClassName')raise_exception(bool) - IfTrue, raiseModuleNotFoundErroron failure instead of returningNone
misc
Miscellaneous helpers.
Location: rick.util.misc
list_duplicates(origin: list) -> list
Return a list of duplicate items found in origin.
object
Object introspection utilities.
Location: rick.util.object
get_attribute_names(obj) -> list
Get a list of public, non-callable attribute names from an object. If the object has a _fieldmap
attribute, its keys are used instead.
class User:
name = "John"
age = 30
def greet(self):
pass
get_attribute_names(User()) # ['age', 'name']
is_object(param) -> bool
Check if param is an object instance (not a type, str, or falsy value).
full_name(obj) -> str
Return the fully qualified class name of an object.
string
String case conversion utilities.
Location: rick.util.string
snake_to_camel(src: str) -> str
Convert snake_case to camelCase.
snake_to_pascal(src: str) -> str
Convert snake_case to PascalCase.
Related Topics
- Base Classes - DI, containers, registries
- Filters - Filters use cast functions internally