Python Database Watcher Library
In a nutshell Python Database Watcher Library is a small library with a set of utilities to help you to monitor and watch the database changes.
Install
> pip install databases_watcher
Supported databases
Redis
Supported modes:
- Queue watch mode:
redis://[[user]:[password]]@host:port/?db=[INT]&queue=[STRING] - Pub/Sub mode:
redis+pubsub://[[user]:[password]]@host:port/?db=[INT]&channel=[STRING] - Changes watch mode (TODO):
redis+watch://[[user]:[password]]@host:port/?db=[INT]&queue=[STRING]
TODO: improve watch mode
Usage examples
Redis
Queue watch mode (Sync mode)
from databases_watcher import connect_database
def main():
redis_watch = connect_database("redis://localhost:6501/?db=0&queue=default")
redis_watch.send_message("hello!")
redis_watch.send_json_message({"message": "hello!"})
print(next(redis_watch.read_messages()))
print(next(redis_watch.read_json_messages()))
if __name__ == '__main__':
main()
Queue watch mode (Async mode)
import asyncio
from databases_watcher import connect_database_async
async def main():
redis_watch = await connect_database_async("redis://localhost:6501/?db=0&queue=default")
await redis_watch.send_message("hello!")
await redis_watch.send_json_message({"message": "hello!"})
async for message in redis_watch.read_messages():
print(message)
break
async for message in redis_watch.read_json_messages():
print(message)
break
if __name__ == '__main__':
asyncio.run(main())
Pub/Sub watch mode (Sync mode)
import time
import threading
from databases_watcher import connect_database
CONNECTION_STRING = "redis+pubsub://localhost:6501/?db=0&channel=default"
def background_read_pubsub():
redis_watch = connect_database(CONNECTION_STRING)
print(next(redis_watch.read_messages()))
print(next(redis_watch.read_json_messages()))
def main():
redis_watch = connect_database(CONNECTION_STRING)
t = threading.Thread(target=background_read_pubsub)
t.start()
time.sleep(2)
redis_watch.send_message("hello!")
redis_watch.send_json_message({"message": "hello!"})
t.join()
if __name__ == '__main__':
main()
Pub/Sub watch mode (Async mode)
import asyncio
from databases_watcher import connect_database_async
CONNECTION_STRING = "redis+pubsub://localhost:6501/?db=0&channel=default"
async def background_read_pubsub():
redis_watch = await connect_database_async(CONNECTION_STRING)
async for message in redis_watch.read_messages():
print(message)
break
async for message in redis_watch.read_json_messages():
print(message)
break
async def main():
redis_watch = await connect_database_async(CONNECTION_STRING)
asyncio.create_task(background_read_pubsub())
await asyncio.sleep(2)
await redis_watch.send_message("hello!")
await redis_watch.send_json_message({"message": "hello!"})
if __name__ == '__main__':
asyncio.run(main())
License
Dictionary Search is Open Source and available under the MIT.
Contributions
Contributions are very welcome. See CONTRIBUTING.md or skim existing tickets to see where you could help out.
Metadata
Release files for databases-watcher 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| databases_watcher-1.0.0.tar.gz | 7.3 kB | Without provenance | Details |
Release files / databases_watcher-1.0.0.tar.gz
| Download URL | databases_watcher-1.0.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8565ccfd15292f3d800941bd2173417d1f1a4208aa6b3d239810ab5aaf0df284
|
|
BLAKE2b-256 checksum How to use checksums |
0d777a294e416fc30ff506132f01a8d5103d2ae1902b24a784a478cc8e400f61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for databases-watcher 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.