-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminimal.py
More file actions
36 lines (26 loc) · 1.01 KB
/
Copy pathminimal.py
File metadata and controls
36 lines (26 loc) · 1.01 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
from time import sleep
import typer
from pydantic import BaseModel, Field
from typer_pydantic_config import get_config, start_config_app
class ApiConfig(BaseModel):
url: str = Field(..., description="The URL of the Endpoint")
username: str = Field("guest", description="Username for the service")
api_key: str = Field(..., description="API key")
app = typer.Typer(
# Setting the name of the app is required. Also this has to be unique.
name="minimal_example_app",
help="Example CLI using Pydantic + Typer.",
)
@app.command()
def mock_request() -> None:
"""Simple command to verify we can read the config."""
config = get_config()
typer.echo(f"Mocking API request at {config.url!r}...")
with typer.progressbar(range(100), length=100) as progress:
for _ in progress:
sleep(0.03)
typer.echo(
f"Request as user {config.username!r} with key {config.api_key!r} successful."
)
if __name__ == "__main__":
start_config_app(app=app, config_cls=ApiConfig)