uf.decorators#

UI metadata decorators for uf.

Provides decorators for annotating functions with UI configuration, grouping, and field specifications.

Functions

deprecated([message])

Decorator to mark a function as deprecated.

field_config(**field_configs)

Decorator to configure specific fields of a function.

get_example(func)

Get example arguments from a function.

get_field_configs(func)

Get field configurations from a function.

get_group(func)

Get group name from a function.

get_ui_config(func)

Get UI configuration from a function.

group(group_name)

Decorator to assign a function to a group.

hidden(func)

Decorator to hide a function from the UI.

is_hidden(func)

Check if a function is hidden from UI.

rate_limit(calls, period)

Decorator to mark a function with rate limiting metadata.

requires_auth(*[, roles, permissions])

Decorator to mark a function as requiring authentication.

ui_config(*[, title, description, group, ...])

Decorator to add UI configuration to functions.

with_example(*example_args, **example_kwargs)

Decorator to attach example arguments to a function.

uf.decorators.deprecated(message=None)[source]#

Decorator to mark a function as deprecated.

Parameters:

message (Optional[str]) – Optional deprecation message

Returns:

Decorator function

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:

Optional[tuple[tuple, dict]]

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:

dict[str, RjsfFieldConfig]

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:

Optional[str]

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:

Optional[dict]

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
uf.decorators.hidden(func)[source]#

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.

Parameters:

func (Callable) – Function to hide

Return type:

Callable

Returns:

Decorated function

Example

>>> @hidden
... def internal_function():
...     pass
uf.decorators.is_hidden(func)[source]#

Check if a function is hidden from UI.

Parameters:

func (Callable) – Function to check

Return type:

bool

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:
  • calls (int) – Number of calls allowed

  • period (int) – Time period in seconds

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:
  • title (Optional[str]) – Custom title for the function in UI

  • description (Optional[str]) – Custom description (overrides docstring)

  • group (Optional[str]) – Group name for organization

  • fields (Optional[dict[str, RjsfFieldConfig]]) – Dictionary mapping parameter names to RjsfFieldConfig

  • hidden (bool) – Whether to hide this function from UI

  • icon (Optional[str]) – Icon identifier for the function

  • order (Optional[int]) – Display order within group

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