A pure python calendar-queue based on asyncio
Project description
calendar-queue
A pure-python calendar queue and library for scheduling events with asyncio.
Many other libraries allow for event/job scheduling but either they are not asynchronous or they are just fire-and-forget.
calendar-queue has two purposes:
- providing the primitives for creating your own scheduler by exporting a
CalendarQueueclass in which events can be awaited - providing a higher level abstraction
Calendarclass that simplifies the usage ofCalendarQueue.
Depending on your needs, you can use one of the two to develop your own event manager/scheduler.
The idea is: we take care of emitting events at the right time, you write the logic for acting accordingly.
Install
pip install calendar-queue
Usage
Quickstart
A minimal, practical example showing how Calendar can schedule and emit events: schedule three reminders a few seconds apart and consume them as they fire.
import asyncio
from datetime import datetime, timedelta
from calendar_queue import Calendar
calendar = Calendar()
async def producer():
for i in range(1, 4):
when = datetime.now() + timedelta(seconds=i * 2)
calendar.schedule(f"Reminder {i}", when=when)
print(f"scheduled Reminder {i} for {when.isoformat()}")
await asyncio.sleep(0.1)
async def consumer():
async for ts, event in calendar:
print(f"{datetime.fromtimestamp(ts).isoformat()}: {event}")
# stop after the last event
if event == "Reminder 3":
calendar.stop()
async def main():
await asyncio.gather(producer(), consumer())
if __name__ == "__main__":
asyncio.run(main())
For more examples and the API reference, see the documentation in the docs folder:
- Tutorials: docs/tutorials
- API reference: docs/api-reference
Development
This library is developed using Python 3.11 and pdm as dependency manager.
Testing is done via github actions and it's done on python versions 3.10, 3.11, 3.12, 3.13, 3.14, 3.14t and on latest ubuntu, macos, windows OSes.
For local development you'll need to have pdm installed, then you can:
- run
pdm installto create the virtual environment and install the dependencies - run
pdm venv activateto activate the virtual environment - run the tests using
pytest - run the linter
pylint src
Contributing
Contributions are welcome! Especially for new tests and for improving documentation and examples.
License
The code in this project is released under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file calendar_queue-0.2.1.tar.gz.
File metadata
- Download URL: calendar_queue-0.2.1.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.26.7 CPython/3.14.4 Linux/6.17.0-1010-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2352e844a4e6399b9f6f8de2760a821fc08e0df914a21afa344e773f0695a3ae
|
|
| MD5 |
6db96e86e4333cdcd714c3b8d4f0cbc0
|
|
| BLAKE2b-256 |
cba4d950a3df6740f138ee9e3b3dc6e128e9adb9d18eb9a662a157f7e3d891d9
|
File details
Details for the file calendar_queue-0.2.1-py3-none-any.whl.
File metadata
- Download URL: calendar_queue-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.26.7 CPython/3.14.4 Linux/6.17.0-1010-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64a2c05067ea9708079850c023c44252b784f9a92f3961c6618123cdb53972cf
|
|
| MD5 |
0e45c7dca2ce2b2566c4034cad6f646f
|
|
| BLAKE2b-256 |
0f92ada289b6a4f56b534489f73df5c8b3f506445020ef0e8882f5e0099bdc8d
|