Skip to content
Open
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rz-sample"
version = "1.5.0"
version = "1.5.1"
description = "A python boilerplate for fastapi and streamlit projects."
authors = ["recursivezero <recursivezero@outlook.com>"]
license = "MIT"
Expand Down
8 changes: 6 additions & 2 deletions src/sample/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
from sample.utils.constants import PORT, PORT_API

from . import __version__

Expand All @@ -23,7 +24,10 @@ def cli(ctx, version):

@cli.command(help="Run the Sample Streamlit app.")
@click.option(
"--port", default=8501, show_default=True, help="Port to run the Streamlit app on."
"--port",
default=int(PORT),
show_default=True,
help="Port to run the Streamlit app on.",
)
def dev(port: int):
from sample.__main__ import main
Expand All @@ -34,7 +38,7 @@ def dev(port: int):
@cli.command(help="Run the Sample FastAPI backend.")
@click.option(
"--port",
default=5000,
default=int(PORT_API),
show_default=True,
help="Port to run the FastAPI backend on.",
)
Expand Down
15 changes: 10 additions & 5 deletions src/sample/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
load_env()
APP_TITLE = ":blue[Greeting Feature]"
DEFAULT_GREETING = "Hello"
DEFAULT_PORT = 8501
FAQ_TITLE = "FAQs"

logging.basicConfig(
Expand All @@ -22,7 +23,7 @@
COMPANY_LOGO = ASSETS_DIR / "logo.png"


def safe_get(secret_path: str, env_key: str = "", default: str = "") -> str:
def safe_get(env_key: str = "", default: str = "") -> str:
"""
Safely retrieve a configuration value from:
1. Streamlit secrets (if secrets.toml exists)
Expand All @@ -42,21 +43,25 @@ def safe_get(secret_path: str, env_key: str = "", default: str = "") -> str:
source = "env"

logging.info(
f"Loaded config for '{env_key or secret_path}' from [{source}]",
f"Loaded config for '{env_key}' from [{source}]",
extra={"color": "yellow"},
)
return value


def get_mongo_config():
return {
"MONGODB_URI": safe_get("mongodb.MONGODB_URI", "MONGODB_URI"),
"DATABASE_NAME": safe_get("mongodb.DATABASE_NAME", "DATABASE_NAME"),
"MONGODB_URI": safe_get("MONGODB_URI"),
"DATABASE_NAME": safe_get("DATABASE_NAME"),
}


PORT = safe_get("PORT", DEFAULT_PORT)
PORT_API = safe_get("API_PORT", int(PORT) + 1)


MONGO_CONFIG = get_mongo_config()
# === Environment Selection ===
ENVIRONMENT = safe_get("env.ENVIRONMENT", "ENVIRONMENT", "development").lower()
ENVIRONMENT = safe_get("ENVIRONMENT", "development").lower()
logging.info(f"Environment: {ENVIRONMENT}", extra={"color": "yellow"})
logging.info(f"Project root: {PROJECT_ROOT}", extra={"color": "yellow"})