Package: mapping-shortcuts
Mapping Shortcutspython package with useful mapping shortcutsInstallationpipinstallmapping-shortcutsContainsFunction decorator for mapping factoryClass decorator for mapping factoryMetaclass for mapping factoryFunction for import all subpackages in packageCLI param parser and processorDecorator factory for mappingfunction decoratorfrommapping_shortcuts.decorsimportcreate_collectordecorator,collection=create_collector(raise_on_duplicate=True,# default: True)@decorator('key1')deffunc1():...@decorator('key2')deffunc2():...print(collection)'''output: {'key1': <function func1 at 0x104adc430>,'key2': <function func2 at 0x104adc4c0>,}'''class decoratorfrommapping_shortcuts.decorsimportcreate_class_collectordecorator,collection=create_class_collector(raise_on_duplicate=True,# default: Truekey_getter=lambdax:x.key# default: lambda x: x.__name__)@decoratorclassSomeClass1:key=123@decoratorclassSomeClass2:key=456print(collection)'''output: {123: <class '__main__.SomeClass1'>,456: <class '__main__.SomeClass2'>,}'''Metaclass factory for mappingimportabcfrommapping_shortcuts.metaimportcreate_collection_metaMetaClass,collections=create_collection_meta(base=abc.ABCMeta,# default: typegetter=lambdax:x.__name__,# default: lambda x: str(x)raise_on_duplicate=True,# default: True)classA(metaclass=MetaClass):...classB(metaclass=MetaClass):...print(collections)'''oputput: {'A': <class '__main__.A'>,'B': <class '__main__.B'>,}'''Function for import all subpackages in packageFor exmaple with have five files:python codeapp/tools.pyempty fileapp/providers/a/__init__.pyempty fileapp/providers/b/__init__.pypython code inapp/providers/a/module.pypython code inapp/providers/b/module.pyapp/tools.pybe like:frommapping_shortcuts.decorsimportcreate_collectordecorator,collection=create_collector()app/providers/a/module.pyis:fromapp.toolsimportdecorator@decorator('A-func')deffunction_a():...app/providers/b/module.pyis:fromapp.toolsimportdecorator@decorator('B-func')deffunction_b():...executeload_package():frommapping_shortcuts.dirtoolsimportload_packagefromapp.toolsimportcollectionload_package('app.providers')print(collection)'''output: {'A-func': <function function_a at 0x104cfa0e0>,'B-func': <function function_b at 0x104cfa290>,}'''CLI param parser and processorfrompydanticimportBaseModel,Fieldfrommapping_shortcuts.cliimportcli_handler,process_sysargv@cli_handler('command1',desc='run handler for command1')defhandler_1(args:dict[str,str|bool])->None:print('command 1 handled!')classArgModel(BaseModel):x:int=Field(alias='--x',description='arg x')y:int=Field(alias='--y',description='arg y')@cli_handler('command2',desc='sum X and Y',model=ArgModel)defhandler_1(args)->None:print(f'{args.x=}')print(f'{args.y=}')print(f'result:{args.x+args.y}')@cli_handler('command3',desc='sum X and Y')defhandler_1(args:ArgModel)->None:print(f'{args.x=}')print(f'{args.y=}')print(f'result:{args.x+args.y}')if__name__=='__main__':process_sysargv(help_msg_header='That\'s my program!',help_msg_run_cmd='python -m project',)Execution:$pythonscript.py

That'smyprogram!
usage:python-mproject[options][command]command:help-seethiscoolmsgagaincommand1-runhandlerforcommand1command2-sumXandY--x-argx--y-argycommand3-sumXandY--x-argx--y-argy$pythonscript.pycommand3--x=123--y=456args.x=123args.y=456result:579