Skip to main content

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.

If you want to decouple the function call from background processes initialiation, you can use the start_background method:

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

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

D = AsyncPause(aprint, filepath="aprint.scheduled.calls")

async def main():
    d = await D.start_background()
    d.set(datetime.now(), "Hello, world!")
    d.set(timedelta(seconds=1), "Hello, world after a second!")
    await asyncio.sleep(3)
asyncio.run(main())

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!

Metadata

Release files for asyncpause 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncpause 0.1.1
File Size Uploaded Provenance Actions
asyncpause-0.1.1.tar.gz 4.0 kB Without provenance Details for asyncpause-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for asyncpause 0.1.1
File Interpreter ABI Platform Actions
asyncpause-0.1.1-py3-none-any.whl Python 3 none any Details for asyncpause-0.1.1-py3-none-any.whl

Total release size: 9.0 kB

Release files / asyncpause-0.1.1.tar.gz

Download URL asyncpause-0.1.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0c688bc834c58ebf976a1e8f74ac8167640b8c57631794a4aeeac46d7798225c
BLAKE2b-256 checksum
How to use checksums
73636c43164ed5794d7366a5225d07abd32bc1d07311d36cca3c2c14f652ae61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.19

Release files / asyncpause-0.1.1-py3-none-any.whl

Download URL asyncpause-0.1.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
579f8e1ead0356039f2d1d6c0ac73a25cf5ff7a5c5652706f3dc1559fd0f439e
BLAKE2b-256 checksum
How to use checksums
41f2c6f8f1b7cb37442dd398002f248d424e8ad449301f6a841dce3883c6c15f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.19

Security for asyncpause 0.1.1

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page