{"id":34701896,"url":"https://github.com/nhairs/sliding-window-counter","last_synced_at":"2026-04-24T17:05:38.396Z","repository":{"id":203925565,"uuid":"710500276","full_name":"nhairs/sliding-window-counter","owner":"nhairs","description":"Time based sliding window counter for Python","archived":false,"fork":false,"pushed_at":"2023-11-03T07:43:15.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-27T14:49:23.193Z","etag":null,"topics":["python","python-library"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nhairs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-26T20:28:24.000Z","updated_at":"2023-12-31T14:26:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"5104c82d-870a-480c-972b-d4343d48449f","html_url":"https://github.com/nhairs/sliding-window-counter","commit_stats":null,"previous_names":["nhairs/sliding-window-counter"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nhairs/sliding-window-counter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhairs%2Fsliding-window-counter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhairs%2Fsliding-window-counter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhairs%2Fsliding-window-counter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhairs%2Fsliding-window-counter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhairs","download_url":"https://codeload.github.com/nhairs/sliding-window-counter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhairs%2Fsliding-window-counter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32232696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","python-library"],"created_at":"2025-12-24T22:53:12.169Z","updated_at":"2026-04-24T17:05:38.391Z","avatar_url":"https://github.com/nhairs.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sliding Window Counter\n\n[![PyPi](https://img.shields.io/pypi/v/sliding-window-counter.svg)](https://pypi.python.org/pypi/sliding-window-counter/)\n[![PyPI - Status](https://img.shields.io/pypi/status/sliding-window-counter)](https://pypi.python.org/pypi/sliding-window-counter/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/sliding-window-counter.svg)](https://github.com/nhairs/sliding-window-counter)\n[![License](https://img.shields.io/github/license/nhairs/sliding-window-counter.svg)](https://github.com/nhairs/sliding-window-counter)\n\n`sliding-window-counter` provides time based sliding window counters. These are useful for tracking things like throughput metrics for long running applications.\n\n## Installation\n### Install via pip\n```shell\npip3 install sliding-window-counter\n```\n\n## Quick Start\n\n```python\n## Creating Counters\n## -----------------------------------------------------------------------------\nimport datetime as dt\nfrom sliding_window_counter import SlidingWindowCounter\n\n# Count across 1 minute with 5 second resolution\nsmall_counter = SlidingWindowCounter(60, 5)\n\n# Count across 1 hour with 1 minute resolution\nlong_counter = SlidingWindowCounter(dt.timedelta(hours=1), dt.timedelta(minutes=1))\n\n# Count across 12 hours with 10 second resolution (not a good idea to be honest)\nlong_and_precise_counter = SlidingWindowCounter(dt.timdelta(hours=12), 10)\n\n## Using Counters\n## -----------------------------------------------------------------------------\nimport random\nimport time\n\nmini_counter = SlidingWindowCounter(10, 1)\n\n# fill it up and check it's state\nfor i in range(20):\n    add = random.randint(1,20)\n    mini_counter.increment(add)\n    print(f\"{i:\u003e3}s Added: {add:\u003c3} Window: {mini_counter.current_total:\u003c6} Total: {mini_counter.grand_total:\u003c6} Avg: {mini_counter.current_throughput:\u003e5.2f}/s\")\n    time.sleep(1)\n\n# Watch it drain\nfor i in range(12):\n    time.sleep(1)\n    print(f\"Window: {mini_counter.current_total:\u003c5} Total: {mini_counter.grand_total:\u003c5} Avg: {mini_counter.current_throughput:\u003e5.2f}/s\")\n```\n\n## Bugs, Feature Requests etc\nTLDR: Please [submit an issue on github](https://github.com/nhairs/sliding-window-counter/issues).\n\nIn the case of bug reports, please help me help you by following best practices [1](https://marker.io/blog/write-bug-report/) [2](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html).\n\nIn the case of feature requests, please provide background to the problem you are trying to solve so to help find a solution that makes the most sense for the library as well as your usecase.\n\n## Development\nThe only development dependency is bash and docker. All actions are run within docker for ease of use. See `./dev.sh help` for commands. Typical commands are `format`, `lint`, `test`, `repl`, `build`.\n\nI am still working through open source licencing and contributing, so not taking PRs at this point in time. Instead raise and issue and I'll try get to it as soon a feasible.\n\n## Licence\nThis project is licenced under the MIT Licence - see [`LICENCE`](https://github.com/nhairs/sliding-window-counter/blob/master/LICENCE).\n\nThis project may include other open source licenced software - see [`NOTICE`](https://github.com/nhairs/sliding-window-counter/blob/master/NOTICE).\n\n## Authors\nA project by Nicholas Hairs - [www.nicholashairs.com](https://www.nicholashairs.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhairs%2Fsliding-window-counter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhairs%2Fsliding-window-counter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhairs%2Fsliding-window-counter/lists"}