Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Remove slowapi (#141)
Browse files Browse the repository at this point in the history
Removed slowapi and rate limiting from tests, templates, and dependencies.
  • Loading branch information
kravetsmic authored Mar 8, 2023
1 parent 59b52c1 commit 050013d
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 62 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.5.0

* Removed rate limit and slow api from project. Updated templates and tests.

# 0.4.9

* Bug fix: Generated code now consistent across Operating Systems
Expand Down
22 changes: 4 additions & 18 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ click==8.1.3
# uvicorn
defusedxml==0.7.1
# via nbconvert
deprecated==1.2.13
# via limits
fastapi==0.92.0
# via unstructured-api-tools (setup.py)
fastjsonschema==2.16.3
Expand Down Expand Up @@ -54,15 +52,13 @@ jupyter-core==5.2.0
# nbformat
jupyterlab-pygments==0.2.2
# via nbconvert
limits==2.8.0
# via slowapi
markupsafe==2.1.2
# via
# jinja2
# nbconvert
mistune==2.0.5
# via nbconvert
mypy==1.0.1
mypy==1.1.1
# via unstructured-api-tools (setup.py)
mypy-extensions==1.0.0
# via mypy
Expand All @@ -74,15 +70,13 @@ nbformat==5.7.3
# via
# nbclient
# nbconvert
packaging==22.0
# via
# limits
# nbconvert
packaging==23.0
# via nbconvert
pandocfilters==1.5.0
# via nbconvert
pkgutil-resolve-name==1.3.10
# via jsonschema
platformdirs==3.0.0
platformdirs==3.1.0
# via jupyter-core
pydantic==1.10.5
# via fastapi
Expand All @@ -104,8 +98,6 @@ six==1.16.0
# via
# bleach
# python-dateutil
slowapi==0.1.7
# via unstructured-api-tools (setup.py)
sniffio==1.3.0
# via anyio
soupsieve==2.4
Expand Down Expand Up @@ -133,7 +125,6 @@ types-urllib3==1.26.25.8
# via types-requests
typing-extensions==4.5.0
# via
# limits
# mypy
# pydantic
# starlette
Expand All @@ -149,12 +140,7 @@ webencodings==0.5.1
# tinycss2
websockets==10.4
# via uvicorn
wrapt==1.15.0
# via deprecated
zipp==3.15.0
# via
# importlib-metadata
# importlib-resources

# The following packages are considered to be unsafe in a requirements file:
# setuptools
2 changes: 0 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#
# pip-compile requirements/dev.in
#
appnope==0.1.3
# via ipython
asttokens==2.2.1
# via stack-data
backcall==0.2.0
Expand Down
8 changes: 3 additions & 5 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#
anyio==3.6.2
# via httpcore
appnope==0.1.3
# via ipython
asttokens==2.2.1
# via
# nbdev
Expand All @@ -25,7 +23,7 @@ certifi==2022.12.7
# httpcore
# httpx
# requests
charset-normalizer==3.0.1
charset-normalizer==3.1.0
# via requests
click==8.1.3
# via
Expand Down Expand Up @@ -91,7 +89,7 @@ pexpect==4.8.0
# via ipython
pickleshare==0.7.5
# via ipython
platformdirs==3.0.0
platformdirs==3.1.0
# via black
pluggy==1.0.0
# via pytest
Expand All @@ -107,7 +105,7 @@ pyflakes==3.0.1
# via flake8
pygments==2.14.0
# via ipython
pytest==7.2.1
pytest==7.2.2
# via pytest-cov
pytest-cov==4.0.0
# via -r requirements/test.in
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
install_requires=[
"click>=8.1",
"fastapi",
"slowapi",
"Jinja2",
"mypy>=0.99",
"nbconvert",
Expand Down
1 change: 0 additions & 1 deletion test_unstructured_api_tools/api/test_file_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def _json_for_one_file(test_file):
)
def test_process_file_1(test_files, test_params, test_type_header, expected_status):
# NOTE(robinson) - Reset the rate limit to avoid 429s in tests
app.state.limiter.reset()
client = TestClient(app)

_files = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@

from fastapi import FastAPI, Request, status

from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from slowapi.util import get_remote_address

from .process_file_1 import router as process_file_1_router


limiter = Limiter(key_func=get_remote_address)
app = FastAPI(
title="Unstructured Pipeline API",
description="""""",
version="1.0.0",
)
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

app.include_router(process_file_1_router)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import os
from typing import List, Union
from fastapi import status, FastAPI, File, Form, Request, UploadFile, APIRouter
from slowapi.errors import RateLimitExceeded
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.util import get_remote_address
from fastapi.responses import PlainTextResponse
import json
from fastapi.responses import StreamingResponse
Expand All @@ -18,14 +15,9 @@
import secrets


limiter = Limiter(key_func=get_remote_address)
app = FastAPI()
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
router = APIRouter()

RATE_LIMIT = os.environ.get("PIPELINE_API_RATE_LIMIT", "1/second")


# pipeline-api
def pipeline_api(
Expand Down Expand Up @@ -100,7 +92,6 @@ async def stream_response(self, send: Send) -> None:


@router.post("/test-project/v1.2.3/process-file-1")
@limiter.limit(RATE_LIMIT)
async def pipeline_1(
request: Request,
files: Union[List[UploadFile], None] = File(default=None),
Expand Down
3 changes: 0 additions & 3 deletions test_unstructured_api_tools/pipelines/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ def test_notebook_file_to_script(sample_notebook, tmpdir):

assert "THIS FILE IS AUTOMATICALLY GENERATED BY UNSTRUCTURED API TOOLS." in script
assert "fastapi" in script
assert "slowapi" in script
assert "pipeline_api" in script


Expand Down Expand Up @@ -333,15 +332,13 @@ def test_convert_notebook_files_to_api(sample_notebook, tmpdir):

assert "THIS FILE IS AUTOMATICALLY GENERATED BY UNSTRUCTURED API TOOLS." in script
assert "fastapi" in script
assert "slowapi" in script
assert "pipeline_api" in script

with open(os.path.join(tmpdir.dirname, "app.py")) as f:
script = f.read()

assert "THIS FILE IS AUTOMATICALLY GENERATED BY UNSTRUCTURED API TOOLS." in script
assert "fastapi" in script
assert "slowapi" in script
assert "The Best API Pipeline!" in script
assert "This is the best API ever!" in script

Expand Down
2 changes: 1 addition & 1 deletion unstructured_api_tools/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.9" # pragma: no cover
__version__ = "0.5.0" # pragma: no cover
8 changes: 0 additions & 8 deletions unstructured_api_tools/pipelines/templates/pipeline_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import os
from typing import List, Union

from fastapi import status, FastAPI, File, Form, Request, UploadFile, APIRouter
from slowapi.errors import RateLimitExceeded
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.util import get_remote_address
from fastapi.responses import PlainTextResponse

import json
Expand All @@ -14,13 +11,9 @@ from base64 import b64encode
from typing import Optional, Mapping, Iterator, Tuple
import secrets

limiter = Limiter(key_func=get_remote_address)
app = FastAPI()
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
router = APIRouter()

RATE_LIMIT = os.environ.get("PIPELINE_API_RATE_LIMIT", "1/second")
{% set default_response_type = optional_param_value_map.pop("response_type", None) %}
{% if default_response_type %}
def is_expected_response_type(media_type, response_type):
Expand Down Expand Up @@ -91,7 +84,6 @@ class MultipartMixedResponse(StreamingResponse):

{% set default_response_schema = optional_param_value_map.pop("response_schema", None) %}
@router.post("{{pipeline_path}}")
@limiter.limit(RATE_LIMIT)
async def pipeline_1(request: Request,
{% if accepts_file %}files: Union[List[UploadFile], None] = File(default=None),{% endif %}
{% if accepts_text %}text_files: Union[List[UploadFile], None] = File(default=None),{% endif %}
Expand Down
7 changes: 0 additions & 7 deletions unstructured_api_tools/pipelines/templates/pipeline_app.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@

from fastapi import FastAPI, Request, status

from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from slowapi.util import get_remote_address

{% for module in module_names -%}
from .{{ module }} import router as {{module}}_router
{% endfor %}

limiter = Limiter(key_func=get_remote_address)
app = FastAPI(
title="{{ title }}",
description="""{{ description }}""",
version="{{ version or '1.0.0' }}",
)
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

{% for module in module_names -%}
app.include_router({{ module }}_router)
Expand Down

0 comments on commit 050013d

Please sign in to comment.