From d848ad0dfd7754b95e240bd24696ff55e3f8ada5 Mon Sep 17 00:00:00 2001 From: Heisenberg208 Date: Tue, 10 Mar 2026 20:32:59 +0530 Subject: [PATCH] [SAM-260015]: feat: add port option for FastAPI and Streamlit commands in Makefile and CLI --- Makefile | 3 ++- README.md | 12 ++++++------ src/sample/api/fast_api.py | 6 +++--- src/sample/cli.py | 10 ++++++++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 81c54d1..66d5d4a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ .PHONY: install lint format type test run api clean PORT ?= 8501 +PORT_API ?= 5000 install: poetry install @@ -24,7 +25,7 @@ dev: poetry run sample dev --port $(PORT) api: - poetry run sample api + poetry run sample api --port $(PORT_API) clean: find . -type d -name "__pycache__" -exec rm -rf {} + diff --git a/README.md b/README.md index 3bd0b97..6581428 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,8 @@ setup `.env.development` and `.env.production` in project root ```bash make dev -#or -poetry run sample dev +#or with custom port +poetry run sample dev --port 8051 ``` @@ -76,8 +76,8 @@ Access: ```bash make api -#OR -poetry run sample api +#OR with custom port +poetry run sample api --port 5000 ``` Access: @@ -134,9 +134,9 @@ pip install sample ## CLI Shortcuts -`sample dev` โ†’ Launch Streamlit UI +`make dev` โ†’ Launch Streamlit UI -`sample api` โ†’ Launch FastAPI +`make api` โ†’ Launch FastAPI current version will be printed on start of above commands. diff --git a/src/sample/api/fast_api.py b/src/sample/api/fast_api.py index 4a79dd7..2411f19 100644 --- a/src/sample/api/fast_api.py +++ b/src/sample/api/fast_api.py @@ -102,7 +102,7 @@ def greet_user(payload: GreetRequest): app.include_router(greet_router) -def start(): +def start(port: int = 5000): import uvicorn print(f"๐Ÿงต {__version__}\n") @@ -112,8 +112,8 @@ def start(): print( "โš ๏ธ Could not connect to the database.Please check database configuration." ) - uvicorn.run("sample.api.fast_api:app", host="127.0.0.1", port=5000, reload=True) + uvicorn.run("sample.api.fast_api:app", host="127.0.0.1", port=port, reload=True) if __name__ == "__main__": - start() + start(port=5000) diff --git a/src/sample/cli.py b/src/sample/cli.py index 46376e9..ccf83be 100644 --- a/src/sample/cli.py +++ b/src/sample/cli.py @@ -32,7 +32,13 @@ def dev(port: int): @cli.command(help="Run the Sample FastAPI backend.") -def api(): +@click.option( + "--port", + default=5000, + show_default=True, + help="Port to run the FastAPI backend on.", +) +def api(port: int): from sample.api.fast_api import start - start() + start(port)