Package: lemiknow
Le Mi Know (when it runs)A small library based onknockknockto get a notification when your function call starts, finishes, or when it crashes during the process with two additional lines of code.Say goodbye to the guessing game, lemiknow will let you know what you need to know, when you need to know.InstallationInstall withpipor equivalent.pipinstalllemiknowThis code has only been tested with Python >= 3.6.UsageThe library is designed to be used in a seamless way, with minimal code modification: you only need to add a decorator on top your main function call. The return value (if there is one) is also reported in the notification.There are currentlyfourways to setup notifications:PlatformOriginal External ContributorUpdated & TestedSlack-YesTelegram-YesDiscord@watkinsmYesMatrix@jcklieYesTo be implemented and tested:PlatformOriginal External ContributorUpdated & TestedMicrosoft Teams@noklamNoText Message@abhishekkrthakurNoemail-NoDesktop@atakanyenelNoSeting up notificationsEvery decorator works the same way but some may require different parameters. Here is a dummy example to show the usual scenariofromlemiknowimportfake_sender@fake_sender(webhook="<your_webhook_url>",message=None,notify_end=True,include_details=True)deffunction_call(parameters):importtimetime.sleep(10)return"Success"# Optional return valueEvery decorator has the following three optional paramenters:message: str
    Optional message to include when notifying the function call.
    default: None
notify_end: bool
    Send a notification when the function finishes (not recommended for short calls).
    default: True
include_details: bool
    Adds extra information on notifications like hostname, start time, etc.
    Can't be False if message is None.
    default: TrueGeneric examples:No message on function end and custom message:fromlemiknowimportfake_sendermessage="This function is fast and doesn't need a notification when it finishes!"@fake_sender(webhook="<your_webhook_url>",message=message,notify_end=False,include_details=True)deffunction_call(parameters):return"So fast"# Optional return valueSend only custom message:fromlemiknowimportfake_sendermessage="I don't need every detail included for this notification"@fake_sender(webhook="<your_webhook_url>",message=message,notify_end=False,include_details=False)deffunction_call(parameters):return"So little detail"# Optional return valueTelegramYou can use Telegram Messenger to get notifications. You'll first have to create your own notification bot by following the three steps provided by Telegramhereand save your API accessTOKEN.Telegram bots are shy and can't send the first message so you'll have to do the first step. By sending the first message, you'll be able to get thechat_idrequired (identification of your messaging room) by visitinghttps://api.telegram.org/bot<YourBOTToken>/getUpdatesand get theintunder the keymessage['chat']['id'].Pythonfromlemiknowimporttelegram_senderCHAT_ID:int=<your_messaging_room_id>@telegram_sender(token="<your_api_token>",chat_id=CHAT_ID)deffunction_call(parameters):importtimetime.sleep(10)return"Success"# Optional return value # Optional return valueCommand-linelemiknowtelegram\--token<your_api_token>\--chat-id<your_messaging_room_id>\sleep10EmailThe service relies onYagmaila GMAIL/SMTP client. You'll need a gmail email address to use it (you can setup onehere, it's free). I recommend creating a new one (rather than your usual one) since you'll have to modify the account's security settings to allow the Python library to access it byTurning on less secure apps.Pythonfromlemiknowimportemail_sender@email_sender(recipient_emails=["<your_email@address.com>","<your_second_email@address.com>"],sender_email="<grandma's_email@gmail.com>")deftrain_your_nicest_model(your_nicest_parameters):importtimetime.sleep(10000)return{'loss':0.9}# Optional return valueCommand-linelemiknowemail\--recipient-emails<your_email@address.com>,<your_second_email@address.com>\--sender-email<grandma's_email@gmail.com>\sleep10Ifsender_emailis not specified, then the first email inrecipient_emailswill be used as the sender's email.Note that launching this will asks you for the sender's email password. It will be safely stored in the system keyring service through thekeyringPython library.SlackSimilarly, you can also use Slack to get notifications. You'll have to get your Slack roomwebhook URLand optionally youruser id(if you want to tag yourself or someone else).Pythonfromlemiknowimportslack_senderwebhook_url="<webhook_url_to_your_slack_room>"@slack_sender(webhook_url=webhook_url,channel="<your_favorite_slack_channel>")deffunction_call(parameters):importtimetime.sleep(10)return"Success"# Optional return value # Optional return valueYou can also specify an optional argument to tag specific people:user_mentions=[<your_slack_id>, <grandma's_slack_id>].Command-linelemiknowslack\--webhook-url<webhook_url_to_your_slack_room>\--channel<your_favorite_slack_channel>\sleep10You can also specify an optional argument to tag specific people:--user-mentions <your_slack_id>,<grandma's_slack_id>.DiscordYou can also use Discord to get notifications. You'll just have to get your Discord channel'swebhook URL.Pythonfromlemiknowimportdiscord_senderwebhook_url="<webhook_url_to_your_discord_channel>"@discord_sender(webhook_url=webhook_url)deffunction_call(parameters):importtimetime.sleep(10)return"Success"# Optional return valueCommand-linelemiknowdiscord\--webhook-url<webhook_url_to_your_discord_channel>\sleep10MatrixMatrixis supported for notifications. The homeserver is the
server on which your user that will send messages is registered. Do not forget the schema for the URL (httporhttps).
You'll have to get the access token for a bot or your own user. The easiest way to obtain it is to look into Riot looking
in the riot settings,Help & About, down the bottom is:Access Token:<click to reveal>. You also need to specify a
room alias to which messages are sent. To obtain the alias in Riot, create a room you want to use, then open the room
settings underRoom Addressesand add an alias.Pythonfromlemiknowimportmatrix_senderHOMESERVER="<url_to_your_home_server>"# e.g. https://matrix.orgTOKEN="<your_auth_token>"# e.g. WiTyGizlr8ntvBXdFfZLctyYROOM="<room_alias"# e.g. #lemiknow:matrix.org@matrix_sender(homeserver=HOMESERVER,token=TOKEN,room=ROOM)deffunction_call(parameters):importtimetime.sleep(10)return"Success"# Optional return valueCommand-linelemiknowmatrix\--homeserver<homeserver>\--token<token>\--room<room>\sleep10The following options have not been tested and updated (but will in future versions)Microsoft TeamsThanks to@noklam, you can also use Microsoft Teams to get notifications. You'll have to get your Team Channelwebhook URL.Pythonfromlemiknowimportteams_sender@teams_sender(token="<webhook_url_to_your_teams_channel>")deftrain_your_nicest_model(your_nicest_parameters):importtimetime.sleep(10)return{'loss':0.9}# Optional return valueCommand-linelemiknowteams\--webhook-url<webhook_url_to_your_teams_channel>\sleep10You can also specify an optional argument to tag specific people:user_mentions=[<your_teams_id>, <grandma's_teams_id>].Text Message (SMS)Thanks to@abhishekkrthakur, you can use Twilio to send text message notifications. You'll have to setup aTwilioaccounthere, which is paid service with competitive prices: for instance in the US, getting a new number and sending one text message through this service respectively cost $1.00 and $0.0075. You'll need to get (a) a phone number, (b) youraccount SIDand (c) yourauthentification token. Some detailhere.Pythonfromlemiknowimportsms_senderACCOUNT_SID:str="<your_account_sid>"AUTH_TOKEN:str="<your_auth_token>"@sms_sender(account_sid=ACCOUNT_SID,auth_token=AUTH_TOKEN,recipient_number="<recipient's_number>",sender_number="<sender's_number>")deftrain_your_nicest_model(your_nicest_parameters):importtimetime.sleep(10)return{'loss':0.9}# Optional return valueCommand-linelemiknowsms\--account-sid<your_account_sid>\--auth-token<your_account_auth_token>\--recipient-number<recipient_number>\--sender-number<sender_number>sleep10Desktop NotificationYou can also get notified from a desktop notification. It is currently only available for MacOS.Pythonfromlemiknowimportdesktop_sender@desktop_sender(title="lemiknow Desktop Notifier")deftrain_your_nicest_model(your_nicest_parameters):importtimetime.sleep(10000)return{"loss":0.9}Command Linelemiknowdesktop\--title'lemiknow Desktop Notifier'\sleep2