uf.organization#

Function grouping and organization for uf.

Provides tools for organizing functions into categories, groups, and hierarchies for better navigation in the UI.

Functions

auto_group_by_module(funcs)

Automatically group functions by their module.

auto_group_by_prefix(funcs[, separator])

Automatically group functions by name prefix.

auto_group_by_tag(funcs[, tag_attr])

Automatically group functions by a tag attribute.

mk_grouped_app(groups, **mk_rjsf_app_kwargs)

Create a uf app with grouped function navigation.

Classes

FunctionGroup(name[, funcs, description, ...])

Group of functions with metadata.

FunctionOrganizer()

Organize functions into groups and hierarchies.

class uf.organization.FunctionGroup(name, funcs=<factory>, description='', icon=None, order=0, collapsed=False)[source]#

Bases: object

Group of functions with metadata.

name#

Name of the group

funcs#

Functions in this group: callables (partials and callable instances are fine; they are named as uf.specs.name_of_func does), or a {name: callable} mapping to name them explicitly

description#

Description of the group

icon#

Optional icon identifier for the group

order#

Display order (lower numbers first)

collapsed#

Whether the group starts collapsed in UI

Example

>>> math_funcs = FunctionGroup(
...     'Math',
...     [add, subtract, multiply, divide],
...     description='Mathematical operations',
...     icon='calculator'
... )
add_function(func, *, name=None)[source]#

Add a function to this group.

Parameters:
  • func (Callable) – Function to add

  • name (Optional[str]) – Explicit name to serve it under (default: its own name). Giving one turns funcs into a {name: callable} mapping.

Return type:

FunctionGroup

Returns:

Self for method chaining

Raises:

ValueError – If a different callable already has that name in the group

get_function_names()[source]#

Get names of all functions in this group.

Return type:

list[str]

Returns:

List of function name strings

property named_funcs: dict[str, Callable]#

{name: callable} of this group, named the way the app serves them.

>>> import functools
>>> g = FunctionGroup('G', [len, functools.partial(int, base=2)])
>>> list(g.named_funcs)
['len', 'int']
class uf.organization.FunctionOrganizer[source]#

Bases: object

Organize functions into groups and hierarchies.

This class provides a fluent interface for building function organization structures that can be used to generate grouped navigation in the UI.

Example

>>> organizer = FunctionOrganizer()
>>> organizer.group('Admin', [user_create, user_delete], icon='shield')
>>> organizer.group('Reports', [generate_report, export_csv], icon='file')
>>> groups = organizer.get_groups()
add_to_group(group_name, func)[source]#

Add a function to an existing group.

Parameters:
  • group_name (str) – Name of the group

  • func (Callable) – Function to add

Return type:

FunctionOrganizer

Returns:

Self for method chaining

Raises:

ValueError – If group doesn’t exist

add_ungrouped(func)[source]#

Add a function without a group.

Parameters:

func (Callable) – Function to add

Return type:

FunctionOrganizer

Returns:

Self for method chaining

get_all_functions()[source]#

Get all functions across all groups.

Return type:

list[Callable]

Returns:

List of all functions

get_groups()[source]#

Get all groups, sorted by order.

Return type:

list[FunctionGroup]

Returns:

List of FunctionGroup objects sorted by order

group(name, funcs=None, *, description='', icon=None, order=0, collapsed=False)[source]#

Create and add a function group.

Parameters:
  • name (str) – Name of the group

  • funcs (Optional[Iterable[Callable]]) – Optional functions to add to group

  • description (str) – Description of the group

  • icon (Optional[str]) – Optional icon identifier

  • order (int) – Display order

  • collapsed (bool) – Whether to start collapsed

Return type:

FunctionGroup

Returns:

The created FunctionGroup

Example

>>> organizer.group(
...     'Database',
...     [save_record, load_record],
...     description='Database operations',
...     icon='database'
... )
to_dict()[source]#

Convert organization to dictionary format.

Return type:

dict

Returns:

Dictionary representation suitable for JSON serialization

Example

>>> org_dict = organizer.to_dict()
>>> # Can be used in templates or APIs
uf.organization.auto_group_by_module(funcs)[source]#

Automatically group functions by their module.

Parameters:

funcs (Iterable[Callable]) – Functions to organize

Return type:

FunctionOrganizer

Returns:

FunctionOrganizer with module-based groups (a functools.partial goes with the module of the function it wraps)

Example

>>> from myapp import user_ops, report_ops
>>> funcs = [user_ops.create, user_ops.delete, report_ops.generate]
>>> organizer = auto_group_by_module(funcs)
uf.organization.auto_group_by_prefix(funcs, separator='_')[source]#

Automatically group functions by name prefix.

Groups functions based on the part of their name before the separator. For example, with separator=”_”:

  • user_create, user_delete → “user” group

  • report_generate, report_export → “report” group

Parameters:
  • funcs (Iterable[Callable]) – Functions to organize

  • separator (str) – Separator character (default: “_”)

Return type:

FunctionOrganizer

Returns:

FunctionOrganizer with auto-generated groups

Example

>>> funcs = [user_create, user_delete, report_generate, admin_reset]
>>> organizer = auto_group_by_prefix(funcs)
>>> # Creates groups: 'user', 'report', 'admin'
uf.organization.auto_group_by_tag(funcs, tag_attr='__uf_group__')[source]#

Automatically group functions by a tag attribute.

Functions can be tagged with a group name using an attribute.

Parameters:
  • funcs (Iterable[Callable]) – Functions to organize

  • tag_attr (str) – Name of the attribute to use for grouping

Return type:

FunctionOrganizer

Returns:

FunctionOrganizer with tag-based groups

Example

>>> def create_user(name: str):
...     pass
>>> create_user.__uf_group__ = 'Admin'
>>>
>>> organizer = auto_group_by_tag([create_user, other_func])
uf.organization.mk_grouped_app(groups, **mk_rjsf_app_kwargs)[source]#

Create a uf app with grouped function navigation.

Parameters:
  • groups (Iterable[FunctionGroup]) – Iterable of FunctionGroup objects

  • **mk_rjsf_app_kwargs – Arguments passed to mk_rjsf_app

Returns:

Configured web application with grouped navigation

Example

>>> admin_group = FunctionGroup('Admin', [user_create, user_delete])
>>> reports_group = FunctionGroup('Reports', [generate_report])
>>> app = mk_grouped_app([admin_group, reports_group])