Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename to django-ratelimiter #2

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: django-limits
name: django-ratelimiter

on: [push]

Expand Down Expand Up @@ -29,5 +29,5 @@ jobs:
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: andriykohut/django-limits
slug: andriykohut/django-ratelimiter

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ lint:
poetry run mypy .

test: run-backends
poetry run pytest --cov django_limits
poetry run pytest --cov django_ratelimiter

test-ci:
poetry run pytest --cov django_limits --cov-report=xml
poetry run pytest --cov django_ratelimiter --cov-report=xml

html-cov: test
poetry run coverage html
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# django-limits
# django-ratelimiter

TBD

## Synopsis

```py
from django.http import HttpRequest, HttpResponse
from django_limits import ratelimit
from django_ratelimiter import ratelimit
from limits.storage import RedisStorage

# defaults, limit all requests
Expand Down
4 changes: 0 additions & 4 deletions django_limits/__init__.py

This file was deleted.

4 changes: 4 additions & 0 deletions django_ratelimiter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django_ratelimiter.decorator import ratelimit
from django_ratelimiter.storage import CacheStorage

__all__ = ["ratelimit", "CacheStorage"]
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from limits.strategies import STRATEGIES, RateLimiter
from limits.storage import Storage
from limits import parse
from django_limits.storage import CacheStorage
from django_limits.types import ViewFunc, P
from django_ratelimiter.storage import CacheStorage
from django_ratelimiter.types import ViewFunc, P


def build_identifiers(
Expand All @@ -34,7 +34,7 @@ def get_rate_limiter(strategy: str, storage: Storage | None = None) -> RateLimit
f"Unknown strategy {strategy}, must be one of {STRATEGIES.keys()}"
)
if not storage:
default_storage = getattr(settings, "DJANGO_LIMITS_CACHE", None)
default_storage = getattr(settings, "DJANGO_RATELIMITER_CACHE", None)
storage = (
default_storage if isinstance(default_storage, Storage) else CacheStorage()
)
Expand All @@ -58,7 +58,7 @@ def wrapper(
) -> HttpResponse:
rate_str = rate(request) if callable(rate) else rate
parsed_rate = parse(rate_str)
if getattr(settings, "DJANGO_LIMITS_ENABLE", True) and (
if getattr(settings, "DJANGO_RATELIMITER_CACHE", True) and (
not methods or request.method in methods
):
identifiers = build_identifiers(func, methods)
Expand Down
4 changes: 2 additions & 2 deletions django_limits/storage.py → django_ratelimiter/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(
**options: float | str | bool,
) -> None:
self.cache_name = cache or cast(
str, getattr(settings, "DJANGO_LIMITS_CACHE", "default")
str, getattr(settings, "DJANGO_RATELIMITER_CACHE", "default")
)
self.cache: BaseCache = caches[self.cache_name]
super().__init__(uri=None, wrap_exceptions=wrap_exceptions, **options)
Expand Down Expand Up @@ -47,7 +47,7 @@ def get_expiry(self, key: str) -> int:

def check(self) -> bool:
try:
self.cache.get("django-limits-check")
self.cache.get("django-ratelimiter-check")
return True
except: # noqa: E722
return False
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "django-limits"
name = "django-ratelimiter"
version = "0.1.0"
description = "Rate-limiting for django"
authors = ["Andrii Kohut <kogut.andriy@gmail.com>"]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from limits import parse
from limits.storage import MemoryStorage, RedisStorage, MemcachedStorage

from django_limits import ratelimit
from django_limits.decorator import get_rate_limiter
from django_ratelimiter import ratelimit
from django_ratelimiter.decorator import get_rate_limiter


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid
import pytest

from django_limits.storage import CacheStorage
from django_ratelimiter.storage import CacheStorage


@pytest.mark.parametrize(
Expand Down