Package: pyfred-cli
Pyfredpyfredhelps you createAlfredworkflows in Python. It has been heavily inspired by a
similar project for Rust,powerpack.It comes with a CLI that helps bootstrapping, maintaining and packaging the workflow.Dependencies are vendored and packaged with the workflow so that they don't need to be installed into the system Python.
See thesection on adding dependenciesfor details.DocumentationThe documentation is deployed toGitHub pages.InstallationYou can install directly from PyPI:pipinstallpyfred-cliUsing the CLIThe CLI knows four commands:new,link,package,vendor.Seepyfred {new,vendor,link,package} -hfor detailed help.NewBootstraps a new workflow with a single script filter and links it into Alfred.It creates a new directory with the given name and copies a "Hello Alfred" workflow there.
The workflow can be used immediately by invoking Alfred with the specified keyword.The following example creates ahellodirectory containing a workflow that can be triggered with thehikeyword. The
result of the selected action is copied to the clipboard.pyfrednewhello-khi-bde.muffix.helloalfred--author=Muffix--description="Hello Alfred".LinkExecuted from a directory bootstrapped by this CLI, it links or relinks the workflow into Alfred.pyfredlinkVendorDownloads the dependencies listed in therequirements.txtfile and vendors them into theworkflow/vendoreddirectory. Doing this avoids having to install them into the system Python interpreter.pyfredvendorPackagePackages the workflow into a*.alfredworkflowfile in thedistdirectory. The file contains the entire workflow and
all dependencies. It can be distributed and imported.pyfredpackageDebug outputThe CLI will log debug output if the--debugflag is passed before the command.Creating a workflowThe classes from thepyfred.modelmodule represent the output expected by Alfred from a script filter.pyfred.workflowprovides a decorator for the entry point of a filter. It preprocesses the input and serialises the
response to stdout, where it is being picked up by the next input.A minimal example for a script filter workflow looks like this:frompyfred.modelimportEnvironment,OutputItem,ScriptFilterOutputfrompyfred.workflowimportscript_filter@script_filterdefmain(script_path:Path,args_from_alfred:list[str],env:Optional[Environment])->ScriptFilterOutput:returnScriptFilterOutput(items=[OutputItem(title="Hello Alfred!")])Adding dependenciesWhen running the workflow, Alfred will use the system Python interpreter to run the script. Third-party libraries are
not available in the interpreter unless explicitly installed. In order to not pollute the system Python, dependencies
can be vendored with the workflow using thepyfred vendorcommand. It is also automatically run withpyfred package.If you add dependencies to yourrequirements.txtfile, you need to runpyfred vendorto download them. You donotneed to prefix the import withvendoredbecause the template adds that directory to thePYTHONPATHvariable when the
workflow runs.IDE setupIf you're using an IDE like PyCharm, you'll want to open the generated directory and set up theworkflowsubdirectory
as the content root. Additionally, you should add theworkflow/vendoreddirectory as source directory in the PyCharm
project settings. This helps it resolve the imports correctly.Adding iconsYou can add an icon for your workflow to theworkflowdirectory in the generated skeleton.
The file name must beicon.pngYou can assign individual icons to your output items. See thepyalfred.model.Iconclass for more details.Distribution through GitHub releasesThe skeleton created bypyfred newcomes with a GitHub action that creates a draft release whenever a tag starting
withvis pushed. To create a tag, rungit tag v1.0.0and push it withgit push origin v1.0.0. When the action
has finished, go to the Releases page of your repository and publish the new release.