forked from MWest2020/presidio-nl-v2
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.py
More file actions
45 lines (39 loc) · 920 Bytes
/
api.py
File metadata and controls
45 lines (39 loc) · 920 Bytes
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
from os import environ
import click
import uvicorn
@click.command()
@click.option(
"--env",
type=click.Choice(["development", "staging", "production"]),
default="development",
)
@click.option(
"--host",
type=str,
default="0.0.0.0",
)
@click.option(
"--port",
type=int,
default=8080,
)
@click.option(
"--workers",
type=int,
default=1,
)
def main(env: str, host: str, port: int, workers: int) -> None:
print(f"Serving on {host}:{port} with {workers} workers in {env} mode.")
# set environment variable with SERVER_MODE
environ["UVICORN_SERVER_MODE"] = env
uvicorn.run(
app="src.api.main:app",
host=host,
port=port,
reload=True if env != "production" else False,
workers=workers,
log_level="warning" if env == "production" else "info",
loop="asyncio",
)
if __name__ == "__main__":
main()