Skip to main content

Count events in rolling time windows and raise when limits are exceeded.

Project description

kanicounter is a small Python library for counting events in rolling time windows. It raises an exception when an event exceeds the allowed count.

Usage

from kanicounter import EventCounter, EventLimitError

counter = EventCounter()
counter.add_watch_window(seconds=60, limit=10)

try:
    counter.add_event()
except EventLimitError as exc:
    print(exc)

limit is the number of events allowed inside the window. For example, seconds=60, limit=10 allows 10 events in the last 60 seconds and raises EventLimitError on the 11th event.

Installation

pip install kanicounter

Requirements

Python 3.8 or newer. There are no runtime dependencies.

Licence

MIT

Authors

kanicounter was written by fx-kirin.

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

kanicounter-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: kanicounter-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for kanicounter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cd8f8ac87de59ef09a87f356bd2b61eaa12fce470fb58bf8aea1f6d93978fb21
MD5 6a2ac27960d278feccacc6ba910ead78
BLAKE2b-256 a5854b4afb9ceae6d4fd573688a1f17dc24922633526e4287d8b1fac6dea9a50

See more details on using hashes here.

Supported by

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