Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samuelcolvin/watchfiles
Simple, modern and fast file watching and code reload in Python.
https://github.com/samuelcolvin/watchfiles
asyncio filesystem inotify inotifywatch notify python uvicorn
Last synced: 4 days ago
JSON representation
Simple, modern and fast file watching and code reload in Python.
- Host: GitHub
- URL: https://github.com/samuelcolvin/watchfiles
- Owner: samuelcolvin
- License: mit
- Created: 2017-10-13T17:31:51.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-12-24T00:15:21.000Z (25 days ago)
- Last Synced: 2025-01-07T00:17:42.446Z (11 days ago)
- Topics: asyncio, filesystem, inotify, inotifywatch, notify, python, uvicorn
- Language: Python
- Homepage: https://watchfiles.helpmanual.io
- Size: 1.49 MB
- Stars: 1,847
- Watchers: 18
- Forks: 109
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-repositories - samuelcolvin/watchfiles - Simple, modern and fast file watching and code reload in Python. (Python)
- awesomeLibrary - watchfiles - Simple, modern and fast file watching and code reload in python. (语言资源库 / python)
README
# watchfiles
[![CI](https://github.com/samuelcolvin/watchfiles/actions/workflows/ci.yml/badge.svg)](https://github.com/samuelcolvin/watchfiles/actions/workflows/ci.yml?query=branch%3Amain)
[![Coverage](https://codecov.io/gh/samuelcolvin/watchfiles/branch/main/graph/badge.svg)](https://codecov.io/gh/samuelcolvin/watchfiles)
[![pypi](https://img.shields.io/pypi/v/watchfiles.svg)](https://pypi.python.org/pypi/watchfiles)
[![CondaForge](https://img.shields.io/conda/v/conda-forge/watchfiles.svg)](https://anaconda.org/conda-forge/watchfiles)
[![license](https://img.shields.io/github/license/samuelcolvin/watchfiles.svg)](https://github.com/samuelcolvin/watchfiles/blob/main/LICENSE)Simple, modern and high performance file watching and code reload in python.
---
**Documentation**: [watchfiles.helpmanual.io](https://watchfiles.helpmanual.io)
**Source Code**: [github.com/samuelcolvin/watchfiles](https://github.com/samuelcolvin/watchfiles)
---
Underlying file system notifications are handled by the [Notify](https://github.com/notify-rs/notify) rust library.
This package was previously named "watchgod",
see [the migration guide](https://watchfiles.helpmanual.io/migrating/) for more information.## Installation
**watchfiles** requires Python 3.8 - 3.13.
```bash
pip install watchfiles
```Binaries are available for:
* **Linux**: `x86_64`, `aarch64`, `i686`, `armv7l`, `musl-x86_64` & `musl-aarch64`
* **MacOS**: `x86_64` & `arm64`
* **Windows**: `amd64` & `win32`Otherwise, you can install from source which requires Rust stable to be installed.
## Usage
Here are some examples of what **watchfiles** can do:
### `watch` Usage
```py
from watchfiles import watchfor changes in watch('./path/to/dir'):
print(changes)
```
See [`watch` docs](https://watchfiles.helpmanual.io/api/watch/#watchfiles.watch) for more details.### `awatch` Usage
```py
import asyncio
from watchfiles import awatchasync def main():
async for changes in awatch('/path/to/dir'):
print(changes)asyncio.run(main())
```
See [`awatch` docs](https://watchfiles.helpmanual.io/api/watch/#watchfiles.awatch) for more details.### `run_process` Usage
```py
from watchfiles import run_processdef foobar(a, b, c):
...if __name__ == '__main__':
run_process('./path/to/dir', target=foobar, args=(1, 2, 3))
```
See [`run_process` docs](https://watchfiles.helpmanual.io/api/run_process/#watchfiles.run_process) for more details.### `arun_process` Usage
```py
import asyncio
from watchfiles import arun_processdef foobar(a, b, c):
...async def main():
await arun_process('./path/to/dir', target=foobar, args=(1, 2, 3))if __name__ == '__main__':
asyncio.run(main())
```
See [`arun_process` docs](https://watchfiles.helpmanual.io/api/run_process/#watchfiles.arun_process) for more details.## CLI
**watchfiles** also comes with a CLI for running and reloading code. To run `some command` when files in `src` change:
```
watchfiles "some command" src
```For more information, see [the CLI docs](https://watchfiles.helpmanual.io/cli/).
Or run
```bash
watchfiles --help
```