Package: alfred5
🎩 AlfredClientSimplest Alfred Client that I use my own projects.Usagepipinstallalfred5Projects dir structurePut your codes andrequirements.txttosrcfoldersInstallalfred5viapipinstallalfred5--target=src/libsAdd the top of themain.pyimportsyssys.path.insert(0,"src/libs")If u want to use different--targetfor ex.useWorkflowClient.run(packagedir=".")Sample of default structure:If u install all of requirements, dont need to createrequirements.txtfile insrcIf you usevscode, add the code that below to.vscode/settings.jsonto debug your file{"python.analysis.extraPaths":["./src/libs"],"python.analysis.exclude":["./src/libs"]}ViaSnippetsClientAPI create custom snippets programmaicallyViaWorkflowClientAPI create custom alfred workflowCraeterequirements.txtfile for your python project to letalfred5installs them if needed 🙃To installfrom requirements.txtdo all import packages insidemain- Useglobalkeyword to access imported packages globallyclient.queryis the query stringclient.page_countis the page count for pagination resultsDont need to addalfred5torequirements.txtUseWorkflowClient.logto log your message to alfred debuggerdebugging alfred workflowwhy this project use stderr for all logging operationUseWorkflowClient(main, cache=True)method to use caching systemJust do it for static (not timebased nor any dynamic stuff) responseDb path isdb/results.ymlalso you can see it from workflow debug panel⭐️ Example Projectfromreimportsubfromurllib.parseimportquote_plusimportsyssys.path.insert(0,"src/libs")fromalfred5importWorkflowClientasyncdefmain(client:WorkflowClient):# To auto install requirements all import operation must be in hereglobalgetfromrequestsimportgetquery=client.queryclient.log(f"my query:{query}")# use it to see your log in workflow debug panel# (use cache=True) Use cache system to quick response instead of old style that below# if client.load_cached_response():#     returnchar_count=str(len(query))word_count=str(len(query.split(" ")))line_count=str(len(query.split("\n")))encoded_string=quote_plus(query)remove_dublication=" ".join(dict.fromkeys(query.split(" ")))upper_case=query.upper()lower_case=query.lower()capitalized=query.capitalize()template=sub(r"[a-zA-Z0-9]","X",query)client.add_result(encoded_string,"Encoded",arg=encoded_string)client.add_result(remove_dublication,"Remove dublication",arg=remove_dublication)client.add_result(upper_case,"Upper Case",arg=upper_case)client.add_result(lower_case,"Lower Case",arg=lower_case)client.add_result(capitalized,"Capitalized",arg=capitalized)client.add_result(template,"Template",arg=template)client.add_result(char_count,"Characters",arg=char_count)client.add_result(word_count,"Words",arg=word_count)client.add_result(line_count,"Lines",arg=line_count)# (use cache=True) to cache result for query instead of old style that below#     if u work with static results (not dynamic; coin price etc.)# client.cache_response()if__name__=="__main__":WorkflowClient.run(main)# WorkflowClient.run(main, cache=True)🔰 How to Create Workflow🪪 LicenseCopyright 2023 Yunus Emre Ak ~ YEmreAk.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.