Package: shadow-scholar
Shadow ScholarTable of ContentsInstallationAvailable ScriptsGetting Access to AWS servicesAdding Your Own ScriptAdding A New ModuleInstallationTo install from PyPI, simply run:pipinstallshadow-scholarAvailable ScriptsEach script is launched withshadow <entrypoint_name>.
For a full list of all entry points, runshadow -l.Getting Access to AWS servicesTo run the scripts that use AWS services, you will need to have access to the following services:AthenaS3The best way to do so is to obtain AWS credentials (access key and secret key) and set them as environment variables.Adding Your Own Script (Application Entry Point)To write your own script for Shadow Scholar, follow these steps:Step 1: Choose where to add your code in Shadow Scholar. It can either be
in an existing module, such asshadow_scholar.collections.athena, or in a
new module.Step 2: Understand that the entry point for your script should be a single
function; think of this as themainfunction.Step 3: Write your main function. For each argument you expect a user might
want to provide from command line, add a corresponding argument to the
function. For example:defmy_script(arg1:str,arg2:int,arg3:bool,arg4:Optional[str]=None,):# Do something with the argumentspassStep 4: Add the cli fromshadow_scholar.clito your script. This will
allow users to run your script from the command line. For example:fromshadow_scholar.cliimportclifromtypingimportOptional@cli(name="scripts_collection.my_script",arguments=...,requirements=...,)defmy_script(arg1:str,arg2:int,arg3:bool,arg4:Optional[str]=None,):# Do something with the argumentspassTheclidecorator takes three arguments: the name of the script, a list
of arguments, and a list of requirements. The name of the script should be
the name a user would use to run the script from the command line. In the
example above, the user would run the script withshadow scripts_collection.my_script.Step 5: Add arguments to your script. Each argument should be an instance
ofshadow_scholar.cli.Argument. For example:fromtypingimportOptionalfromshadow_scholar.cliimportArgument,cli@cli(name="scripts_collection.my_script",arguments=[Argument(name="arg1",type=str,help="This is the first argument",),Argument(name="arg2",type=int,help="This is the second argument",),Argument(name="arg3",type=bool,help="This is the third argument",),Argument(name="arg4",type=str,help="This is the fourth argument",default=None,),],requirements=...,)defmy_script(arg1:str,arg2:int,arg3:bool,arg4:Optional[str]=None,):# Do something with the argumentspassYou should have as many Arguments as you have arguments to your main function.Step 6: Add requirements to your script. Each requirement should be an
in the format used byrequirements.txt. When using optional requirements,
make sure to wrap them in awith safe_import()statement at the top of your
script. For example:fromtypingimportOptionalfromshadow_scholar.cliimportArgument,cli,safe_importwithsafe_import()assafe:# this will not fail if pandas is not installedimportpandasaspd@cli(name="scripts_collection.my_script",arguments=[Argument(name="arg1",type=str,help="This is the first argument",),Argument(name="arg2",type=int,help="This is the second argument",),Argument(name="arg3",type=bool,help="This is the third argument",),Argument(name="arg4",type=str,help="This is the fourth argument",default=None,),],requirements=["pandas>=1.0.0",],)defmy_script(arg1:str,arg2:int,arg3:bool,arg4:Optional[str]=None,):# Do something with the argumentspassStep 7: Import the function in the__init__.pyfile of the module. For
example, if you added your script toshadow_scholar/examples.py, you would
add the following toshadow_scholar/__init__.py:fromshadow_scholar.examplesimportmy_scriptAdding A New Module (Available to All Scripts/as a Dependency)Adding a module to Shadow Scholar is as easy as adding a script, but,
instead of decorating the main entry-point function withcli, you need
to use the@requiredecorator. For example:fromshadow_scholar.cliimportrequire,safe_importwithsafe_import():importrequests@require(["requests>=2.0.0"])defmodule_function():# Do something with requestsrequests.get(...)