what is it?
file watching and code reload in python
installation
pip install watchfilesusage
watch
paths watched can be directories or files, directories are watched recursively - changes in subdirectories are also detected
from watchfiles import watch
for changes in watch('./path/to/dir'):
print(changes)awatch
asynchronous equivalent of watch using threads to wait for changes
import asyncio
from watchfiles import awatch
async def main():
async for changes in awatch('/path/to/dir'):
print(changes)
asyncio.run(main())cli
watchfiles --filter python 'celery -A django_celery_example worker --loglevel=info'--filter pythontellswatchfilesto only watchpyfiles.- By default,
watchfileswill watch the current directory and all subdirectories