Skip to content
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.PHONY: install lint format type test run api clean

PORT ?= 8501
PORT_API ?= 5000
install:
poetry install

Expand All @@ -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 {} +
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```

Expand All @@ -76,8 +76,8 @@ Access: <http://localhost:8501>

```bash
make api
#OR
poetry run sample api
#OR with custom port
poetry run sample api --port 5000
```

Access: <http://127.0.0.1:5000>
Expand Down Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions src/sample/api/fast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
10 changes: 8 additions & 2 deletions src/sample/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)