-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (55 loc) · 2.1 KB
/
Copy pathmain.py
File metadata and controls
67 lines (55 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import argparse
import os
import uvicorn
from src.utils.logging import configure_logging
# Get host and port from environment variables or use defaults
HOST = os.getenv("HOST", "127.0.0.1")
PORT = int(os.getenv("PORT", "8000"))
WORKERS_COUNT = int(os.getenv("WORKERS_COUNT", "1"))
def start_api(host, port, workers, datasets_path, enable_debug=False, log_level="INFO"):
if log_level.upper() == "DEBUG":
enable_debug = True
if os.getenv("DATASETS_PATH") is None:
os.environ["DATASETS_PATH"] = datasets_path
configure_logging(enable_debug, log_level)
uvicorn_log_level = log_level.lower() if log_level.lower() in ["critical", "error", "warning", "info", "debug", "trace"] else "info"
uvicorn.run("src.api.api:app", host=host, port=port, workers=workers, log_level=uvicorn_log_level)
def main():
parser = argparse.ArgumentParser(
description="A lightweight FastAPI service that exposes endpoints to interact with Zarr datasets stored in a Simple Storage Service (S3)"
)
parser.add_argument(
"-p", "--port", type=int, default=int(PORT), help="Port to run the API server on"
)
parser.add_argument(
"-H", "--host", type=str, default=HOST, help="Host to run the API server on"
)
parser.add_argument(
"-w",
"--workers",
type=int,
default=int(WORKERS_COUNT),
help="Number of worker processes for handling requests",
)
parser.add_argument(
"-d", "--debug", action="store_true", help="Enable debug logging"
)
parser.add_argument(
"--log-level",
type=str,
choices=["TRACE", "DEBUG", "INFO", "SUCCESS", "WARNING", "ERROR", "CRITICAL"],
default="INFO",
help="Set the log level for the application",
)
parser.add_argument(
"--datasets-path",
type=str,
default="/",
help="Path to the datasets configuration file",
)
args = parser.parse_args()
start_api(
args.host, args.port, args.workers, args.datasets_path, enable_debug=args.debug, log_level=args.log_level
)
if __name__ == "__main__":
main()