https://github.com/github30/win11toast
  
  
    Toast notifications for Windows 10 and 11 based on WinRT 
    https://github.com/github30/win11toast
  
notifications python toast windows windows-runtime windows11 winrt
        Last synced: 7 months ago 
        JSON representation
    
Toast notifications for Windows 10 and 11 based on WinRT
- Host: GitHub
- URL: https://github.com/github30/win11toast
- Owner: GitHub30
- License: mit
- Created: 2022-08-07T13:47:28.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-08T08:08:38.000Z (over 1 year ago)
- Last Synced: 2025-04-04T09:06:57.289Z (7 months ago)
- Topics: notifications, python, toast, windows, windows-runtime, windows11, winrt
- Language: Python
- Homepage: https://pypi.org/project/win11toast/
- Size: 81.1 KB
- Stars: 274
- Watchers: 6
- Forks: 18
- Open Issues: 23
- 
            Metadata Files:
            - Readme: README.md
- License: LICENSE
 
Awesome Lists containing this project
README
          [](https://badge.fury.io/py/win11toast)
[](https://badge.fury.io/py/win11toast)
# win11toast
Toast notifications for Windows 10 and 11 based on [WinRT](https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts)

## Installation
```bash
pip install win11toast
```
## Usage
```python
from win11toast import toast
toast('Hello Python🐍')
```

https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-text
### Body
```python
from win11toast import toast
toast('Hello Python', 'Click to open url', on_click='https://www.python.org')
```

### Wrap text
```python
from win11toast import toast
toast('Hello', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum accusantium porro numquam aspernatur voluptates cum, odio in, animi nihil cupiditate molestias laborum. Consequatur exercitationem modi vitae. In voluptates quia obcaecati!')
```

### Run Python script on Click
```python
from win11toast import toast
toast('Hello Pythonista', 'Click to run python script', on_click=r'C:\Users\Admin\Downloads\handler.pyw')
# {'arguments': 'C:\\Users\\Admin\\Downloads\\handler.pyw', 'user_input': {}}
```
Since the current directory when executing the script is `C:\Windows\system32`, use `os.chdir()` accordingly.
e.g. [handler.pyw](https://gist.github.com/GitHub30/dae1b257c93d8315ea38554c9554a2ad)
On Windows, you can run a Python script in the background using the pythonw.exe executable, which will run your program with no visible process or way to interact with it.
https://stackoverflow.com/questions/9705982/pythonw-exe-or-python-exe

### Callback
```python
from win11toast import toast
toast('Hello Python', 'Click to open url', on_click=lambda args: print('clicked!', args))
# clicked! {'arguments': 'http:', 'user_input': {}}
```
### Icon
```python
from win11toast import toast
toast('Hello', 'Hello from Python', icon='https://unsplash.it/64?image=669')
```

#### Square
```python
from win11toast import toast
icon = {
    'src': 'https://unsplash.it/64?image=669',
    'placement': 'appLogoOverride'
}
toast('Hello', 'Hello from Python', icon=icon)
```

### Image
```python
from win11toast import toast
toast('Hello', 'Hello from Python', image='https://4.bp.blogspot.com/-u-uyq3FEqeY/UkJLl773BHI/AAAAAAAAYPQ/7bY05EeF1oI/s800/cooking_toaster.png')
```

https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-image
#### Hero
```python
from win11toast import toast
image = {
    'src': 'https://4.bp.blogspot.com/-u-uyq3FEqeY/UkJLl773BHI/AAAAAAAAYPQ/7bY05EeF1oI/s800/cooking_toaster.png',
    'placement': 'hero'
}
toast('Hello', 'Hello from Python', image=image)
```

### Progress
```python
from time import sleep
from win11toast import notify, update_progress
notify(progress={
    'title': 'YouTube',
    'status': 'Downloading...',
    'value': '0',
    'valueStringOverride': '0/15 videos'
})
for i in range(1, 15+1):
    sleep(1)
    update_progress({'value': i/15, 'valueStringOverride': f'{i}/15 videos'})
update_progress({'status': 'Completed!'})
```

Attributes
https://docs.microsoft.com/en-ca/uwp/schemas/tiles/toastschema/element-progress
https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-progress-bar
### Audio
```python
from win11toast import toast
toast('Hello', 'Hello from Python', audio='ms-winsoundevent:Notification.Looping.Alarm')
```
Available audio
https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-audio
##### From URL
```python
from win11toast import toast
toast('Hello', 'Hello from Python', audio='https://nyanpass.com/nyanpass.mp3')
```
##### From file
```python
from win11toast import toast
toast('Hello', 'Hello from Python', audio=r"C:\Users\Admin\Downloads\nyanpass.mp3")
```
I don't know how to add custom audio please help.
https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/custom-audio-on-toasts
#### Loop
```python
from win11toast import toast
toast('Hello', 'Hello from Python', audio={'loop': 'true'})
```
```python
from win11toast import toast
toast('Hello', 'Hello from Python', audio={'src': 'ms-winsoundevent:Notification.Looping.Alarm', 'loop': 'true'})
```
### Silent🤫
```python
from win11toast import toast
toast('Hello Python🐍', audio={'silent': 'true'})
```
### Speak🗣
```python
from win11toast import toast
toast('Hello Python🐍', dialogue='Hello world')
```
### OCR👀
```python
from win11toast import toast
toast(ocr='https://i.imgur.com/oYojrJW.png')
```

```python
from win11toast import toast
toast(ocr={'lang': 'ja', 'ocr': r'C:\Users\Admin\Downloads\hello.png'})
```

### Long duration
```python
from win11toast import toast
toast('Hello Python🐍', duration='long')
```
displayed for 25 seconds
https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-toast
### No timeout
```python
from win11toast import toast
toast('Hello Python🐍', scenario='incomingCall')
```
The scenario your toast is used for, like an alarm, reminder, incomingCall or urgent.
https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-toast#:~:text=None-,scenario,-The%20scenario%20your

### Button
```python
from win11toast import toast
toast('Hello', 'Hello from Python', button='Dismiss')
# {'arguments': 'http:Dismiss', 'user_input': {}}
```

```python
from win11toast import toast
toast('Hello', 'Hello from Python', button={'activationType': 'protocol', 'arguments': 'https://google.com', 'content': 'Open Google'})
# {'arguments': 'https://google.com', 'user_input': {}}
```

```python
from win11toast import toast
toast('Hello', 'Click a button', buttons=['Approve', 'Dismiss', 'Other'])
```

https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-action
#### Play music or Open Explorer
```python
from win11toast import toast
buttons = [
    {'activationType': 'protocol', 'arguments': 'C:\Windows\Media\Alarm01.wav', 'content': 'Play'},
    {'activationType': 'protocol', 'arguments': 'file:///C:/Windows/Media', 'content': 'Open Folder'}
]
toast('Music Player', 'Download Finished', buttons=buttons)
```

### Input
```python
from win11toast import toast
toast('Hello', 'Type anything', input='reply', button='Send')
# {'arguments': 'http:Send', 'user_input': {'reply': 'Hi there'}}
```

```python
from win11toast import toast
toast('Hello', 'Type anything', input='reply', button={'activationType': 'protocol', 'arguments': 'http:', 'content': 'Send', 'hint-inputId': 'reply'})
# {'arguments': 'http:', 'user_input': {'reply': 'Hi there'}}
```

https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-input
### Selection
```python
from win11toast import toast
toast('Hello', 'Which do you like?', selection=['Apple', 'Banana', 'Grape'], button='Submit')
# {'arguments': 'dismiss', 'user_input': {'selection': 'Grape'}}
```


### No arguments
```python
from win11toast import toast
toast()
```

### Non blocking
```python
from win11toast import notify
notify('Hello Python', 'Click to open url', on_click='https://www.python.org')
```
### Async
```python
from win11toast import toast_async
async def main():
    await toast_async('Hello Python', 'Click to open url', on_click='https://www.python.org')
```
### Jupyter
```python
from win11toast import notify
notify('Hello Python', 'Click to open url', on_click='https://www.python.org')
```

```python
from win11toast import toast_async
await toast_async('Hello Python', 'Click to open url', on_click='https://www.python.org')
```

```python
import urllib.request
from pathlib import Path
src = str(Path(urllib.request.urlretrieve("https://i.imgur.com/p9dRdtP.jpg")[0]).absolute())
from win11toast import toast_async
await toast_async('にゃんぱすー', audio='https://nyanpass.com/nyanpass.mp3', image={'src': src, 'placement':'hero'})
```
```python
from win11toast import toast_async
await toast_async('Hello Python🐍', dialogue='にゃんぱすー')
```
## Debug
```python
from win11toast import toast
xml = """
    
        
            Jill Bender
            Check out where we camped last weekend! It was incredible, wish you could have come on the backpacking trip!
            
            
        
    
    
        
        
    
"""
toast(xml=xml)
```

[Notifications Visualizer](https://www.microsoft.com/store/apps/notifications-visualizer/9nblggh5xsl1)

# Acknowledgements
- [winsdk_toast](https://github.com/Mo-Dabao/winsdk_toast)
- [Windows-Toasts](https://github.com/DatGuy1/Windows-Toasts)
- [MarcAlx/notification.py](https://gist.github.com/MarcAlx/443358d5e7167864679ffa1b7d51cd06)