Skip to main content

a Python library to schedule and persist async function calls, ensuring they run exactly when you need them, even after restarts.

Project description

asyncpause

Welcome to asyncpause! This nifty little Python library is here to make sure your async functions get called exactly when you want them to, even if your program decides to take a little nap in between. With asyncpause, you can schedule async function calls to run at specific times or after certain delays, and it will ensure they are executed even after a restart. Say goodbye to missed calls and hello to punctuality!

Features

  • Schedule async function calls with ease.
  • Save call details to disk to survive restarts.
  • Load and execute scheduled calls automatically.
  • Supports delays in seconds, timedeltas, or specific datetime objects.

Installation

You can install asyncpause via pip:

pip install asyncpause

Usage

Here's a quick example to get you started. Let's schedule some functions and watch the magic happen.

import asyncio
from datetime import datetime, timedelta
from asyncpause import AsyncPause

async def main():
    async def aprint(*args, **kwargs):
        print(*args, **kwargs)

    d = await AsyncPause.setup(aprint)
    # you can also pass a filepath to save the scheduled calls
    # or in_memory=True to keep them in memory :)
    d.set(datetime.now(), "Hello, world!")
    d.set(timedelta(seconds=5), "Hello, world! 5 sec spent!")
    d.set(timedelta(seconds=1), "Hello, world after a second!")
    d.set(timedelta(seconds=2))
    await asyncio.sleep(6)

asyncio.run(main())

In this example, the aprint function its just an example. Just run this script, and watch your console get filled with timely greetings.

How It Works

  1. Initialization: Create an AsyncPause object with your target function.
  2. Scheduling: Use the set method to schedule your function calls. You can specify a delay in seconds, a timedelta, or a specific datetime.
  3. Persistence: The library saves the scheduled calls to a file (or keeps them in memory if you prefer).
  4. Execution: It runs the scheduled calls at the right time, even after restarts.

Why asyncpause?

Because sometimes you just need your async functions to be fashionably late, not never! This library handles all the tedious work of saving, loading, and running your scheduled functions, so you can focus on writing great code without worrying about time.

Contributing

Feel free to fork this repository, make some changes, and submit a pull request. Whether it's fixing bugs, adding features, or just improving documentation, all contributions are welcome!

License

This project is licensed under The Unlicense.

Conclusion

asyncpause is your go-to tool for scheduling async function calls in Python. It's reliable, easy to use, and ensures that your functions are called when they should be, no matter what. So why wait? Install asyncpause today and give your async functions the punctuality they deserve!


P.S. Why was the async function always on time? Because it knew how to await its turn!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncpause-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

asyncpause-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file asyncpause-0.1.0.tar.gz.

File metadata

  • Download URL: asyncpause-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.15.2 CPython/3.12.3 Darwin/23.4.0

File hashes

Hashes for asyncpause-0.1.0.tar.gz
Algorithm Hash digest
SHA256 14b64250c631b10da244c6985d02ccbe61012ca934e04eb84f03668ea92e996c
MD5 08b546f31fba55e6db407359eb3a4d8f
BLAKE2b-256 621ae3df06ba36c9d43c0fff7c003918a27e787eb4ceb08788618582a268782a

See more details on using hashes here.

File details

Details for the file asyncpause-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: asyncpause-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.15.2 CPython/3.12.3 Darwin/23.4.0

File hashes

Hashes for asyncpause-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33353a0c70fceab034fe30e751257cd34be42bc7af8af8b8ff2aadffd461b76b
MD5 82c54877e296f332ea11c142de50ceea
BLAKE2b-256 813ea551f70e28ad4d640ddc10b3a905e9ae8699792edb9a3cbf292c5847139c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page