uf.decorators#
UI metadata decorators for uf.
Provides decorators for annotating functions with UI configuration, grouping, and field specifications.
Functions
|
Decorator to mark a function as deprecated. |
|
Decorator to configure specific fields of a function. |
|
Get example arguments from a function. |
|
Get field configurations from a function. |
|
Get group name from a function. |
|
Get UI configuration from a function. |
|
Decorator to assign a function to a group. |
|
Decorator to hide a function from the UI. |
|
Check if a function is hidden from UI. |
|
Decorator to mark a function with rate limiting metadata. |
|
Decorator to mark a function as requiring authentication. |
|
Decorator to add UI configuration to functions. |
|
Decorator to attach example arguments to a function. |
- uf.decorators.deprecated(message=None)[source]#
Decorator to mark a function as deprecated.
Example
>>> @deprecated("Use new_function instead") ... def old_function(): ... pass
- uf.decorators.field_config(**field_configs)[source]#
Decorator to configure specific fields of a function.
- Parameters:
**field_configs (
RjsfFieldConfig) – Keyword arguments mapping parameter names to configs- Returns:
Decorator function
Example
>>> from uf.rjsf_config import get_field_config >>> >>> @field_config( ... email=get_field_config('email'), ... bio=get_field_config('multiline_text') ... ) ... def create_profile(email: str, bio: str): ... pass
- uf.decorators.get_example(func)[source]#
Get example arguments from a function.
- Parameters:
func (
Callable) – Function to get example from- Return type:
- Returns:
Tuple of (args, kwargs) or None if no example
Example
>>> example = get_example(my_function) >>> if example: ... args, kwargs = example ... result = my_function(*args, **kwargs)
- uf.decorators.get_field_configs(func)[source]#
Get field configurations from a function.
- Parameters:
func (
Callable) – Function to get field configs from- Return type:
- Returns:
Dictionary mapping parameter names to RjsfFieldConfig
Example
>>> field_configs = get_field_configs(my_function) >>> if 'email' in field_configs: ... print(field_configs['email'].format)
- uf.decorators.get_group(func)[source]#
Get group name from a function.
- Parameters:
func (
Callable) – Function to get group from- Return type:
- Returns:
Group name or None
Example
>>> group = get_group(my_function) >>> if group: ... print(f"Function is in group: {group}")
- uf.decorators.get_ui_config(func)[source]#
Get UI configuration from a function.
- Parameters:
func (
Callable) – Function to get config from- Return type:
- Returns:
Configuration dictionary or None if not configured
Example
>>> config = get_ui_config(my_function) >>> if config: ... print(config['title'])
- uf.decorators.group(group_name)[source]#
Decorator to assign a function to a group.
Simpler alternative to ui_config when you only need to set the group.
- Parameters:
group_name (
str) – Name of the group- Returns:
Decorator function
Example
>>> @group("Admin") ... def delete_user(user_id: int): ... pass
Decorator to hide a function from the UI.
The function will still be callable via the API but won’t appear in the UI navigation.
Example
>>> @hidden ... def internal_function(): ... pass
Check if a function is hidden from UI.
- Parameters:
func (
Callable) – Function to check- Return type:
- Returns:
True if function is hidden, False otherwise
Example
>>> if not is_hidden(my_function): ... # Show in UI ... pass
- uf.decorators.rate_limit(calls, period)[source]#
Decorator to mark a function with rate limiting metadata.
This is metadata-only; actual rate limiting must be implemented separately.
- Parameters:
- Returns:
Decorator function
Example
>>> @rate_limit(calls=10, period=60) # 10 calls per minute ... def send_email(to: str, subject: str): ... pass
- uf.decorators.requires_auth(*, roles=None, permissions=None)[source]#
Decorator to mark a function as requiring authentication.
This is metadata-only; actual authentication must be implemented separately in the application layer.
- Parameters:
- Returns:
Decorator function
Example
>>> @requires_auth(roles=['admin'], permissions=['user:delete']) ... def delete_user(user_id: int): ... pass
- uf.decorators.ui_config(*, title=None, description=None, group=None, fields=None, hidden=False, icon=None, order=None)[source]#
Decorator to add UI configuration to functions.
This decorator attaches metadata to functions that uf can use to customize the generated UI.
- Parameters:
- Returns:
Decorator function
Example
>>> @ui_config( ... title="User Registration", ... group="Admin", ... fields={'email': RjsfFieldConfig(format='email')} ... ) ... def register_user(email: str, name: str): ... pass
- uf.decorators.with_example(*example_args, **example_kwargs)[source]#
Decorator to attach example arguments to a function.
This can be used to provide example/test data that appears in the UI.
- Parameters:
*example_args – Example positional arguments
**example_kwargs – Example keyword arguments
- Returns:
Decorator function
Example
>>> @with_example(x=10, y=20) ... def add(x: int, y: int) -> int: ... return x + y