{"id":27299958,"url":"https://github.com/parisaalizadeh2003/saferatelimiter-","last_synced_at":"2025-04-12T00:50:12.269Z","repository":{"id":283097218,"uuid":"950674903","full_name":"ParisaAlizadeh2003/SafeRateLimiter-","owner":"ParisaAlizadeh2003","description":"This Python project implements a Rate Limiter decorator that restricts the number of function calls within a specified time window. It helps control execution flow and prevent excessive function calls.","archived":false,"fork":false,"pushed_at":"2025-03-18T14:24:46.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T00:50:04.136Z","etag":null,"topics":["api-rate-limiting","decorators-python","limiting","performance","pytest","python","rate-limiter","software-development","throttling","time-based-limiter"],"latest_commit_sha":null,"homepage":"","language":"Python","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/ParisaAlizadeh2003.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-18T14:18:42.000Z","updated_at":"2025-03-18T14:35:47.000Z","dependencies_parsed_at":"2025-03-18T15:44:20.522Z","dependency_job_id":null,"html_url":"https://github.com/ParisaAlizadeh2003/SafeRateLimiter-","commit_stats":null,"previous_names":["parisaalizadeh2003/saferatelimiter-"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ParisaAlizadeh2003%2FSafeRateLimiter-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ParisaAlizadeh2003%2FSafeRateLimiter-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ParisaAlizadeh2003%2FSafeRateLimiter-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ParisaAlizadeh2003%2FSafeRateLimiter-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ParisaAlizadeh2003","download_url":"https://codeload.github.com/ParisaAlizadeh2003/SafeRateLimiter-/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501902,"owners_count":21114681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["api-rate-limiting","decorators-python","limiting","performance","pytest","python","rate-limiter","software-development","throttling","time-based-limiter"],"created_at":"2025-04-12T00:50:11.638Z","updated_at":"2025-04-12T00:50:12.251Z","avatar_url":"https://github.com/ParisaAlizadeh2003.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SafeRateLimiter\n\nA Python project that implements a **Rate Limiter** decorator to restrict function calls within a specified time window. This helps prevent excessive calls and protects system resources.\n\n---\n\n## Description\n\nRateLimiterPy uses Python decorators to monitor and control how many times a function can be called within a given time frame. By storing timestamps of recent calls in a local list (closure), the decorator allows a function to run only if the number of calls in the defined period is below a specified limit. If the limit is exceeded, a `ValueError` is raised.\n\n---\n\n## Features\n\n- **Function Call Control:** Limit the number of function executions per time period.\n- **High-Resolution Timing:** Uses `time.perf_counter()` for precise measurement.\n- **Closure-Based Storage:** Keeps call timestamps local to each decorated function.\n- **Simple and Extensible:** Easy to apply to any function requiring rate limiting.\n\n---\n\n## Installation\n\n1. **Clone the repository:**\n   ```bash\n   git clone https://github.com/YourUsername/RateLimiterPy.git\n   cd RateLimiterPy\n   ```\n\n2. **(Optional) Create a virtual environment and install dependencies:**\n   ```bash\n   python -m venv env\n   source env/bin/activate  # On Windows use: env\\Scripts\\activate\n   pip install -r requirements.txt\n   ```\n   *Note: This project uses only standard libraries (e.g., `time`, `functools`), so no additional packages are required.*\n\n---\n\n## Usage\n\nApply the rate limiter decorator to your function by specifying the maximum number of allowed calls and the time window (in seconds).\n\n### **Example:**\n\n```python\nimport time\nfrom Rate_Limiter import Rate_limiter\n\n@Rate_limiter(3, 5)\ndef say_hello(name):\n    return f\"Hello to {name}\"\n\nif __name__ == \"__main__\":\n    # This loop will raise a ValueError once the rate limit is exceeded\n    for _ in range(10):\n        try:\n            print(say_hello(\"sara\"))\n        except ValueError as e:\n            print(e)\n    \n    time.sleep(5)  # Wait for the rate limiter to reset\n    print(say_hello(\"ali\"))\n```\n\n---\n\n## Testing\n\nTests are written using **pytest** to verify the behavior under various conditions including valid calls, invalid (exceeding) calls, and edge cases.\n\n### **Run Tests:**\n\n1. Ensure you have pytest installed:\n   ```bash\n   pip install pytest\n   ```\n\n2. Run the tests:\n   ```bash\n   pytest\n   ```\n\n### **Example Test Cases:**\n\n- **Valid Calls:** Confirm that functions return correct values when calls are within limits.\n- **Invalid Calls:** Verify that a `ValueError` is raised when the rate limit is exceeded.\n- **Edge Cases:** Test boundary conditions with appropriate use of `time.sleep()` to reset the limiter.\n\n---\n\n## Contributing\n\nContributions are welcome! If you have suggestions or improvements:\n- Fork the repository.\n- Create a feature branch.\n- Commit your changes and open a pull request.\n\n---\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n## Contact\n\nFor any questions or issues, please open an issue on GitHub or contact [Parisa Alizadeh](mailto:parisaalizadeg13821382@gmail.com).\n\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparisaalizadeh2003%2Fsaferatelimiter-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparisaalizadeh2003%2Fsaferatelimiter-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparisaalizadeh2003%2Fsaferatelimiter-/lists"}