diff --git a/docs/index.md b/docs/index.md index 71fa99f..b389cd6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -104,6 +104,9 @@ sequenceDiagram STAR->>STAR: Lookup handlers by path STAR->>+PROC: Send event and context + alt "Process is cold" + PROC<<->>HAND: Import handler + end PROC->>+HAND: Invoke handler HAND->>-PROC: Result PROC->>-STAR: Result diff --git a/docs/user_guide/custom_entrypoint.md b/docs/user_guide/custom_entrypoint.md index 60b997b..a7bf3a1 100644 --- a/docs/user_guide/custom_entrypoint.md +++ b/docs/user_guide/custom_entrypoint.md @@ -24,9 +24,10 @@ Here's an example `smyth_conf.py` file: ```python title="my_project/etc/smyth_conf.py" linenums="1" import uvicorn -from starlette.requests import Request -from smyth.smyth import Smyth from smyth.server.app import SmythStarlette +from smyth.smyth import Smyth +from starlette.requests import Request + def my_handler(event, context): return {"statusCode": 200, "body": "Hello, World!"} @@ -46,16 +47,17 @@ smyth = Smyth() smyth.add_handler( name="hello", path="/hello", - lambda_handler=my_handler, + lambda_handler_path="smyth_run.my_handler", timeout=1, concurrency=1, - event_data_generator=my_event_data_generator, + event_data_function=my_event_data_generator, ) app = SmythStarlette(smyth=smyth, smyth_path_prefix="/smyth") if __name__ == "__main__": - uvicorn.run("smyth_conf:app", host="0.0.0.0", port=8080, reload=True) + uvicorn.run("smyth_run:app", host="0.0.0.0", port=8080, reload=True) + ``` Normally, the handler would be imported, but including the custom event generator in this file is a good use case. Use the `SmythStarlette` subclass of `Starlette` - it ensures all subprocesses are run at server start and killed on stop (using ASGI Lifetime). Create a Smyth instance and pass it to your `SmythStarlette` instance. Here, you can fine-tune logging, change Uvicorn settings, etc. diff --git a/docs/user_guide/non_http.md b/docs/user_guide/non_http.md index 683c610..54f0238 100644 --- a/docs/user_guide/non_http.md +++ b/docs/user_guide/non_http.md @@ -43,7 +43,7 @@ In your `etc` directory, create a `smyth_run.py` file. smyth.add_handler( name="hello", path="/hello", - lambda_handler=my_handler, + lambda_handler_path="smyth_run.my_handler", timeout=60, concurrency=10, strategy_generator=round_robin, @@ -65,6 +65,7 @@ In your `etc` directory, create a `smyth_run.py` file. if __name__ == "__main__": with smyth: asyncio.run(main()) + ``` ### Import and Declare the Basics @@ -118,7 +119,7 @@ smyth = Smyth() smyth.add_handler( name="hello", path="/hello", - lambda_handler=my_handler, + lambda_handler_path="smyth_run.my_handler", timeout=60, concurrency=10, strategy_generator=round_robin, diff --git a/pyproject.toml b/pyproject.toml index 8d1913a..45d04cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,7 @@ Source = "https://github.com/mirumee/smyth" [project.optional-dependencies] dev = ["ipdb"] types = ["mypy>=1.0.0", "pytest", "types-toml", "pytest-asyncio"] -docs = ["mkdocs-material"] +docs = ["mkdocs-material", "termynal"] [tool.hatch.version] path = "src/smyth/__about__.py" @@ -156,7 +156,7 @@ docstring-code-line-length = 80 [tool.ruff.lint] select = ["E", "F", "G", "I", "N", "Q", "UP", "C90", "T20", "TID"] -unfixable = ["UP007"] # typer does not handle PEP604 annotations +unfixable = ["UP007"] # typer does not handle PEP604 annotations [tool.ruff.lint.flake8-tidy-imports] ban-relative-imports = "all" diff --git a/tests/conftest.py b/tests/conftest.py index d74b249..18264d2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,12 +9,6 @@ @pytest.fixture(autouse=True) def anyio_backend(): - # uvloop is not available for Python 3.13 - # https://github.com/MagicStack/uvloop/issues/622 - # waiting for 0.21.0 release - # import sys - # if sys.version_info < (3, 13): - # return "asyncio" return "asyncio", {"use_uvloop": True}