diff options
Diffstat (limited to 'python-aiohttp-ratelimiter.spec')
-rw-r--r-- | python-aiohttp-ratelimiter.spec | 480 |
1 files changed, 480 insertions, 0 deletions
diff --git a/python-aiohttp-ratelimiter.spec b/python-aiohttp-ratelimiter.spec new file mode 100644 index 0000000..20aa0d9 --- /dev/null +++ b/python-aiohttp-ratelimiter.spec @@ -0,0 +1,480 @@ +%global _empty_manifest_terminate_build 0 +Name: python-aiohttp-ratelimiter +Version: 4.1.1 +Release: 1 +Summary: A simple rate limiter for aiohttp.web +License: MIT +URL: https://jgltechnologies.com/aiohttplimiter +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/ef/fa/497f1debf5ae3ae1f44d6e60b860afdc99402018d630f907cf9480f2c5e1/aiohttp-ratelimiter-4.1.1.tar.gz +BuildArch: noarch + + +%description +<a href="https://jgltechnologies.com/discord">
+<img src="https://discord.com/api/guilds/844418702430175272/embed.png">
+</a>
+
+# aiohttp-ratelimiter
+
+aiohttp-ratelimiter is a rate limiter for the aiohttp.web framework.
+This is a new library, and we are always looking for people to contribute. If you see something wrong with the code or want to add a feature, please create a pull request
+on <a href="https://jgltechnologies.com/aiohttplimiter">our github</a>.
+
+
+Install from git
+```
+python -m pip install git+https://github.com/JGLTechnologies/aiohttp-ratelimiter
+```
+
+Install from pypi
+```
+python -m pip install aiohttp-ratelimiter
+// if redis is being used
+python -m pip install aiohttp-ratelimiter[redis]
+// if memcached is being used
+python -m pip install aiohttp-ratelimiter[memcached]
+```
+
+<br>
+
+
+Example
+
+```python
+from aiohttp import web
+from aiohttplimiter import default_keyfunc, Limiter
+from aiohttplimiter.redis_limiter import RedisLimiter
+from aiohttplimiter.memcached_limiter import MemcachedLimiter
+
+app = web.Application()
+routes = web.RouteTableDef()
+
+# In Memory
+limiter = Limiter(keyfunc=default_keyfunc)
+# Redis
+limiter = RedisLimiter(keyfunc=default_keyfunc, uri="redis://localhost:6379")
+# Memcached
+limiter = MemcachedLimiter(keyfunc=default_keyfunc, uri="memcached://localhost:11211")
+
+@routes.get("/")
+# This endpoint can only be requested 1 time per second per IP address
+@limiter.limit("1/second")
+async def home(request):
+ return web.Response(text="test")
+
+app.add_routes(routes)
+web.run_app(app)
+```
+
+<br>
+
+You can exempt an IP from rate limiting using the exempt_ips kwarg.
+
+```python
+from aiohttplimiter import Limiter, default_keyfunc
+from aiohttp import web
+
+app = web.Application()
+routes = web.RouteTableDef()
+
+# 192.168.1.245 is exempt from rate limiting.
+# Keep in mind that exempt_ips takes a set not a list.
+limiter = Limiter(keyfunc=default_keyfunc, exempt_ips={"192.168.1.245"})
+
+@routes.get("/")
+@limiter.limit("3/5minutes")
+async def test(request):
+ return web.Response(text="test")
+
+app.add_routes(routes)
+web.run_app(app)
+```
+
+<br>
+
+You can create your own error handler by using the error_handler kwarg.
+
+```python
+from aiohttplimiter import Allow, RateLimitExceeded, Limiter, default_keyfunc
+from aiohttp import web
+
+def handler(request: web.Request, exc: RateLimitExceeded):
+ # If for some reason you want to allow the request, return aiohttplimitertest.Allow().
+ if some_condition:
+ return Allow()
+ return web.Response(text=f"Too many requests", status=429)
+
+limiter = Limiter(keyfunc=default_keyfunc, error_handler=handler)
+```
+
+<br>
+
+If multiple paths use one handler like this:
+```python
+@routes.get("/")
+@routes.get("/home")
+@limiter.limit("5/hour")
+def home(request):
+ return web.Response(text="Hello")
+```
+
+<br>
+
+Then they will have separate rate limits. To prevent this use the path_id kwarg.
+
+```python
+@routes.get("/")
+@routes.get("/home")
+@limiter.limit("2/3days", path_id="home")
+def home(request):
+ return web.Response(text="Hello")
+```
+
+<br>
+
+Views Example
+
+```python
+@routes.view("/")
+class Home(View):
+ @limiter.limit("1/second")
+ def get(self: web.Request):
+ return web.Response(text="hello")
+```
+
+
+
+
+
+ + +%package -n python3-aiohttp-ratelimiter +Summary: A simple rate limiter for aiohttp.web +Provides: python-aiohttp-ratelimiter +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-aiohttp-ratelimiter +<a href="https://jgltechnologies.com/discord">
+<img src="https://discord.com/api/guilds/844418702430175272/embed.png">
+</a>
+
+# aiohttp-ratelimiter
+
+aiohttp-ratelimiter is a rate limiter for the aiohttp.web framework.
+This is a new library, and we are always looking for people to contribute. If you see something wrong with the code or want to add a feature, please create a pull request
+on <a href="https://jgltechnologies.com/aiohttplimiter">our github</a>.
+
+
+Install from git
+```
+python -m pip install git+https://github.com/JGLTechnologies/aiohttp-ratelimiter
+```
+
+Install from pypi
+```
+python -m pip install aiohttp-ratelimiter
+// if redis is being used
+python -m pip install aiohttp-ratelimiter[redis]
+// if memcached is being used
+python -m pip install aiohttp-ratelimiter[memcached]
+```
+
+<br>
+
+
+Example
+
+```python
+from aiohttp import web
+from aiohttplimiter import default_keyfunc, Limiter
+from aiohttplimiter.redis_limiter import RedisLimiter
+from aiohttplimiter.memcached_limiter import MemcachedLimiter
+
+app = web.Application()
+routes = web.RouteTableDef()
+
+# In Memory
+limiter = Limiter(keyfunc=default_keyfunc)
+# Redis
+limiter = RedisLimiter(keyfunc=default_keyfunc, uri="redis://localhost:6379")
+# Memcached
+limiter = MemcachedLimiter(keyfunc=default_keyfunc, uri="memcached://localhost:11211")
+
+@routes.get("/")
+# This endpoint can only be requested 1 time per second per IP address
+@limiter.limit("1/second")
+async def home(request):
+ return web.Response(text="test")
+
+app.add_routes(routes)
+web.run_app(app)
+```
+
+<br>
+
+You can exempt an IP from rate limiting using the exempt_ips kwarg.
+
+```python
+from aiohttplimiter import Limiter, default_keyfunc
+from aiohttp import web
+
+app = web.Application()
+routes = web.RouteTableDef()
+
+# 192.168.1.245 is exempt from rate limiting.
+# Keep in mind that exempt_ips takes a set not a list.
+limiter = Limiter(keyfunc=default_keyfunc, exempt_ips={"192.168.1.245"})
+
+@routes.get("/")
+@limiter.limit("3/5minutes")
+async def test(request):
+ return web.Response(text="test")
+
+app.add_routes(routes)
+web.run_app(app)
+```
+
+<br>
+
+You can create your own error handler by using the error_handler kwarg.
+
+```python
+from aiohttplimiter import Allow, RateLimitExceeded, Limiter, default_keyfunc
+from aiohttp import web
+
+def handler(request: web.Request, exc: RateLimitExceeded):
+ # If for some reason you want to allow the request, return aiohttplimitertest.Allow().
+ if some_condition:
+ return Allow()
+ return web.Response(text=f"Too many requests", status=429)
+
+limiter = Limiter(keyfunc=default_keyfunc, error_handler=handler)
+```
+
+<br>
+
+If multiple paths use one handler like this:
+```python
+@routes.get("/")
+@routes.get("/home")
+@limiter.limit("5/hour")
+def home(request):
+ return web.Response(text="Hello")
+```
+
+<br>
+
+Then they will have separate rate limits. To prevent this use the path_id kwarg.
+
+```python
+@routes.get("/")
+@routes.get("/home")
+@limiter.limit("2/3days", path_id="home")
+def home(request):
+ return web.Response(text="Hello")
+```
+
+<br>
+
+Views Example
+
+```python
+@routes.view("/")
+class Home(View):
+ @limiter.limit("1/second")
+ def get(self: web.Request):
+ return web.Response(text="hello")
+```
+
+
+
+
+
+ + +%package help +Summary: Development documents and examples for aiohttp-ratelimiter +Provides: python3-aiohttp-ratelimiter-doc +%description help +<a href="https://jgltechnologies.com/discord">
+<img src="https://discord.com/api/guilds/844418702430175272/embed.png">
+</a>
+
+# aiohttp-ratelimiter
+
+aiohttp-ratelimiter is a rate limiter for the aiohttp.web framework.
+This is a new library, and we are always looking for people to contribute. If you see something wrong with the code or want to add a feature, please create a pull request
+on <a href="https://jgltechnologies.com/aiohttplimiter">our github</a>.
+
+
+Install from git
+```
+python -m pip install git+https://github.com/JGLTechnologies/aiohttp-ratelimiter
+```
+
+Install from pypi
+```
+python -m pip install aiohttp-ratelimiter
+// if redis is being used
+python -m pip install aiohttp-ratelimiter[redis]
+// if memcached is being used
+python -m pip install aiohttp-ratelimiter[memcached]
+```
+
+<br>
+
+
+Example
+
+```python
+from aiohttp import web
+from aiohttplimiter import default_keyfunc, Limiter
+from aiohttplimiter.redis_limiter import RedisLimiter
+from aiohttplimiter.memcached_limiter import MemcachedLimiter
+
+app = web.Application()
+routes = web.RouteTableDef()
+
+# In Memory
+limiter = Limiter(keyfunc=default_keyfunc)
+# Redis
+limiter = RedisLimiter(keyfunc=default_keyfunc, uri="redis://localhost:6379")
+# Memcached
+limiter = MemcachedLimiter(keyfunc=default_keyfunc, uri="memcached://localhost:11211")
+
+@routes.get("/")
+# This endpoint can only be requested 1 time per second per IP address
+@limiter.limit("1/second")
+async def home(request):
+ return web.Response(text="test")
+
+app.add_routes(routes)
+web.run_app(app)
+```
+
+<br>
+
+You can exempt an IP from rate limiting using the exempt_ips kwarg.
+
+```python
+from aiohttplimiter import Limiter, default_keyfunc
+from aiohttp import web
+
+app = web.Application()
+routes = web.RouteTableDef()
+
+# 192.168.1.245 is exempt from rate limiting.
+# Keep in mind that exempt_ips takes a set not a list.
+limiter = Limiter(keyfunc=default_keyfunc, exempt_ips={"192.168.1.245"})
+
+@routes.get("/")
+@limiter.limit("3/5minutes")
+async def test(request):
+ return web.Response(text="test")
+
+app.add_routes(routes)
+web.run_app(app)
+```
+
+<br>
+
+You can create your own error handler by using the error_handler kwarg.
+
+```python
+from aiohttplimiter import Allow, RateLimitExceeded, Limiter, default_keyfunc
+from aiohttp import web
+
+def handler(request: web.Request, exc: RateLimitExceeded):
+ # If for some reason you want to allow the request, return aiohttplimitertest.Allow().
+ if some_condition:
+ return Allow()
+ return web.Response(text=f"Too many requests", status=429)
+
+limiter = Limiter(keyfunc=default_keyfunc, error_handler=handler)
+```
+
+<br>
+
+If multiple paths use one handler like this:
+```python
+@routes.get("/")
+@routes.get("/home")
+@limiter.limit("5/hour")
+def home(request):
+ return web.Response(text="Hello")
+```
+
+<br>
+
+Then they will have separate rate limits. To prevent this use the path_id kwarg.
+
+```python
+@routes.get("/")
+@routes.get("/home")
+@limiter.limit("2/3days", path_id="home")
+def home(request):
+ return web.Response(text="Hello")
+```
+
+<br>
+
+Views Example
+
+```python
+@routes.view("/")
+class Home(View):
+ @limiter.limit("1/second")
+ def get(self: web.Request):
+ return web.Response(text="hello")
+```
+
+
+
+
+
+ + +%prep +%autosetup -n aiohttp-ratelimiter-4.1.1 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-aiohttp-ratelimiter -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 4.1.1-1 +- Package Spec generated |