Skip to main content

❤️ cardaio

A Python library for adjustable delays.

The main use case is when you want to periodically pull something from a third-party system but you don't know exactly how often the system will have updates. For example, you're monitoring a news website for a particular topic and you want to pull news as soon as they are available but at the same time you don't want to send too many requests when there are no updates.

😎 Features

  • 🐍 Pure Python.
  • 🐎 asyncio-first with synchronous API available.
  • 🛡 Fully type-annotated and type-safe.
  • 🪶 Zero-dependency.
  • 🔧 Highly configurable.
  • ☑️ 100% test coverage.

📦 Installation

python3 -m pip install cardaio

🛠️ Usage

from cardaio import Heartbeat

async def run() -> None:
    hb = Heartbeat(
        # never pull more often than every 1s.
        fastest=1,
        # never pull less often than every 1m.
        slowest=60,
        # start with 10s between iterations.
        start=10,
    )
    async for _ in hb:
        # Pull messages from a remote system.
        msgs = await pull_messages()
        # If there are more than 5 messages,
        # start pulling more often.
        if msgs > 5:
            hb.faster()
        # If there are no messages,
        # pull less often
        elif not msgs:
            hb.slower()
        ...  # do something with messages

🖨 Acknowledgments

The project is inspired by cardio.go Go script introduced by Xe Iaso in the Anything can be a message queue if you use it wrongly enough blog post. The implementation and API are different, though, to make it pythonic and user-friendly.

Release files for cardaio 1.0.0

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

Source distribution (sdist)

Source distribution for cardaio 1.0.0
File Size Uploaded
cardaio-1.0.0.tar.gz 6.6 kB Details

Built distribution (wheel)

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

Total release size: 11.4 kB

Release files / cardaio-1.0.0.tar.gz

Download URL cardaio-1.0.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c749d326d68c85c859bfe2fe659ab4bcabfa8bcc0bb058b30506267e902fc57c
BLAKE2b-256 checksum
How to use checksums
48b54f402c22aedde8665674a23225fd1c3507fd4d91b8214de6f1a0634a6f36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.2

Release files / cardaio-1.0.0-py3-none-any.whl

Download URL cardaio-1.0.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3796b1ef45eacce3ebbd8f1d6c2d468f728f1c36037527f88be581652921bc5d
BLAKE2b-256 checksum
How to use checksums
07792f926cdd9d586b335d0108be52f965c8a7eb35ad54056227f0411e167ef7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

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