deepctl-cmd-requests 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: deepctl-cmd-requests
3
+ Version: 0.0.2
4
+ Summary: Requests history command for deepctl
5
+ Author-email: Deepgram <devrel@deepgram.com>
6
+ Maintainer-email: Deepgram <devrel@deepgram.com>
7
+ License-Expression: MIT
8
+ Keywords: deepgram,cli,requests,history
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ Requires-Dist: deepctl-core>=0.1.10
18
+ Requires-Dist: click>=8.0.0
19
+ Requires-Dist: rich>=13.0.0
20
+ Requires-Dist: pydantic>=2.0.0
21
+
22
+ # deepctl-cmd-requests
23
+
24
+ > Part of [deepctl](https://github.com/deepgram/cli) — Official Deepgram CLI
25
+
26
+ Requests history command for deepctl
27
+
28
+ ## Installation
29
+
30
+ This package is included with deepctl and does not need to be installed separately.
31
+
32
+ ### Install deepctl
33
+
34
+ ```bash
35
+ # Install with pip
36
+ pip install deepctl
37
+
38
+ # Or install with uv
39
+ uv tool install deepctl
40
+
41
+ # Or install with pipx
42
+ pipx install deepctl
43
+
44
+ # Or run without installing
45
+ uvx deepctl --help
46
+ pipx run deepctl --help
47
+ ```
48
+
49
+ ## Commands
50
+
51
+ | Command | Entry Point |
52
+ |---------|-------------|
53
+ | `deepctl requests` | `deepctl_cmd_requests.command:RequestsCommand` |
54
+
55
+ ## Dependencies
56
+
57
+ - `click>=8.0.0`
58
+ - `rich>=13.0.0`
59
+ - `pydantic>=2.0.0`
60
+
61
+ ## License
62
+
63
+ MIT — see [LICENSE](../../LICENSE)
@@ -0,0 +1,42 @@
1
+ # deepctl-cmd-requests
2
+
3
+ > Part of [deepctl](https://github.com/deepgram/cli) — Official Deepgram CLI
4
+
5
+ Requests history command for deepctl
6
+
7
+ ## Installation
8
+
9
+ This package is included with deepctl and does not need to be installed separately.
10
+
11
+ ### Install deepctl
12
+
13
+ ```bash
14
+ # Install with pip
15
+ pip install deepctl
16
+
17
+ # Or install with uv
18
+ uv tool install deepctl
19
+
20
+ # Or install with pipx
21
+ pipx install deepctl
22
+
23
+ # Or run without installing
24
+ uvx deepctl --help
25
+ pipx run deepctl --help
26
+ ```
27
+
28
+ ## Commands
29
+
30
+ | Command | Entry Point |
31
+ |---------|-------------|
32
+ | `deepctl requests` | `deepctl_cmd_requests.command:RequestsCommand` |
33
+
34
+ ## Dependencies
35
+
36
+ - `click>=8.0.0`
37
+ - `rich>=13.0.0`
38
+ - `pydantic>=2.0.0`
39
+
40
+ ## License
41
+
42
+ MIT — see [LICENSE](../../LICENSE)
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "deepctl-cmd-requests"
7
+ version = "0.0.2" # x-release-please-version
8
+ description = "Requests history command for deepctl"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ authors = [{ name = "Deepgram", email = "devrel@deepgram.com" }]
12
+ maintainers = [{ name = "Deepgram", email = "devrel@deepgram.com" }]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.10",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ ]
21
+ keywords = ["deepgram", "cli", "requests", "history"]
22
+ requires-python = ">=3.10"
23
+ dependencies = [
24
+ "deepctl-core>=0.1.10",
25
+ "click>=8.0.0",
26
+ "rich>=13.0.0",
27
+ "pydantic>=2.0.0",
28
+ ]
29
+
30
+ [project.scripts]
31
+
32
+ [project.entry-points."deepctl.commands"]
33
+ requests = "deepctl_cmd_requests.command:RequestsCommand"
34
+
35
+ [tool.setuptools]
36
+ package-dir = { "" = "src" }
37
+
38
+ [tool.setuptools.packages.find]
39
+ where = ["src"]
40
+ include = ["deepctl_cmd_requests*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ """Requests history command for deepctl."""
@@ -0,0 +1,262 @@
1
+ """Requests history command for deepctl."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import datetime, timedelta
6
+ from typing import Any
7
+
8
+ from deepctl_core import (
9
+ AuthManager,
10
+ BaseCommand,
11
+ BaseResult,
12
+ Config,
13
+ DeepgramClient,
14
+ )
15
+ from rich.console import Console
16
+ from rich.table import Table
17
+
18
+ from .models import RequestInfo, RequestsResult
19
+
20
+ console = Console()
21
+
22
+
23
+ class RequestsCommand(BaseCommand):
24
+ """Command for viewing API request history."""
25
+
26
+ name = "requests"
27
+ help = "View Deepgram API request history"
28
+ short_help = "Request history"
29
+
30
+ requires_auth = True
31
+ requires_project = True
32
+ ci_friendly = True
33
+
34
+ examples = [
35
+ "dg requests",
36
+ "dg requests --limit 50",
37
+ "dg requests --status failed",
38
+ "dg requests --endpoint listen --method streaming",
39
+ "dg requests --show REQUEST_ID",
40
+ "dg requests --last-week",
41
+ ]
42
+ agent_help = (
43
+ "View API request history for the current project. "
44
+ "Filter by status, endpoint, method, and date range. "
45
+ "Requires authentication and a project ID."
46
+ )
47
+
48
+ def get_arguments(self) -> list[dict[str, Any]]:
49
+ return [
50
+ {
51
+ "names": ["--show", "-s"],
52
+ "help": "Show details for a specific request",
53
+ "type": str,
54
+ "is_option": True,
55
+ },
56
+ {
57
+ "names": ["--status"],
58
+ "help": "Filter by status (succeeded, failed)",
59
+ "type": str,
60
+ "is_option": True,
61
+ },
62
+ {
63
+ "names": ["--endpoint"],
64
+ "help": "Filter by endpoint (listen, read, speak, agent)",
65
+ "type": str,
66
+ "is_option": True,
67
+ },
68
+ {
69
+ "names": ["--method"],
70
+ "help": "Filter by method (sync, async, streaming)",
71
+ "type": str,
72
+ "is_option": True,
73
+ },
74
+ {
75
+ "names": ["--limit"],
76
+ "help": "Maximum number of results (default: 10)",
77
+ "type": int,
78
+ "is_option": True,
79
+ "default": 10,
80
+ },
81
+ {
82
+ "names": ["--page"],
83
+ "help": "Page number for pagination",
84
+ "type": int,
85
+ "is_option": True,
86
+ },
87
+ {
88
+ "names": ["--start-date"],
89
+ "help": "Start date (YYYY-MM-DD)",
90
+ "type": str,
91
+ "is_option": True,
92
+ },
93
+ {
94
+ "names": ["--end-date"],
95
+ "help": "End date (YYYY-MM-DD)",
96
+ "type": str,
97
+ "is_option": True,
98
+ },
99
+ {
100
+ "names": ["--last-week"],
101
+ "help": "Show requests from last 7 days",
102
+ "is_flag": True,
103
+ "is_option": True,
104
+ },
105
+ {
106
+ "names": ["--last-day"],
107
+ "help": "Show requests from last 24 hours",
108
+ "is_flag": True,
109
+ "is_option": True,
110
+ },
111
+ {
112
+ "names": ["--project-id", "-p"],
113
+ "help": "Project ID (uses configured project if not provided)",
114
+ "type": str,
115
+ "is_option": True,
116
+ },
117
+ ]
118
+
119
+ def handle(
120
+ self,
121
+ config: Config,
122
+ auth_manager: AuthManager,
123
+ client: DeepgramClient,
124
+ **kwargs: Any,
125
+ ) -> BaseResult:
126
+ show_request = kwargs.get("show")
127
+ project_id = kwargs.get("project_id")
128
+
129
+ try:
130
+ if show_request:
131
+ return self._show_request(client, show_request, project_id)
132
+ else:
133
+ return self._list_requests(
134
+ client,
135
+ project_id,
136
+ status=kwargs.get("status"),
137
+ endpoint=kwargs.get("endpoint"),
138
+ method=kwargs.get("method"),
139
+ limit=kwargs.get("limit"),
140
+ page=kwargs.get("page"),
141
+ start_date=kwargs.get("start_date"),
142
+ end_date=kwargs.get("end_date"),
143
+ last_week=kwargs.get("last_week", False),
144
+ last_day=kwargs.get("last_day", False),
145
+ )
146
+ except Exception as e:
147
+ console.print(f"[red]Error:[/red] {e}")
148
+ return BaseResult(status="error", message=str(e))
149
+
150
+ def _list_requests(
151
+ self,
152
+ client: DeepgramClient,
153
+ project_id: str | None,
154
+ status: str | None = None,
155
+ endpoint: str | None = None,
156
+ method: str | None = None,
157
+ limit: int | None = None,
158
+ page: int | None = None,
159
+ start_date: str | None = None,
160
+ end_date: str | None = None,
161
+ last_week: bool = False,
162
+ last_day: bool = False,
163
+ ) -> BaseResult:
164
+ limit = limit or 10
165
+
166
+ # Resolve date ranges
167
+ start_dt = None
168
+ end_dt = None
169
+ if last_week:
170
+ start_dt = datetime.now() - timedelta(days=7)
171
+ end_dt = datetime.now()
172
+ elif last_day:
173
+ start_dt = datetime.now() - timedelta(days=1)
174
+ end_dt = datetime.now()
175
+ elif start_date:
176
+ start_dt = datetime.fromisoformat(start_date)
177
+ end_dt = datetime.fromisoformat(end_date) if end_date else datetime.now()
178
+
179
+ console.print("[blue]Fetching request history...[/blue]")
180
+
181
+ result = client.list_requests(
182
+ project_id=project_id,
183
+ start=start_dt,
184
+ end=end_dt,
185
+ limit=limit,
186
+ page=page,
187
+ status=status,
188
+ endpoint=endpoint,
189
+ method=method,
190
+ )
191
+
192
+ requests_raw = result.get("requests", [])
193
+ if not requests_raw:
194
+ console.print("[yellow]No requests found[/yellow]")
195
+ return RequestsResult(status="info", message="No requests found")
196
+
197
+ req_models: list[RequestInfo] = []
198
+ table = Table(title="API Requests", show_header=True, header_style="bold blue")
199
+ table.add_column("Time", style="dim")
200
+ table.add_column("Endpoint", style="cyan")
201
+ table.add_column("Method")
202
+ table.add_column("Status")
203
+ table.add_column("Duration")
204
+ table.add_column("Request ID", style="dim")
205
+
206
+ for r in requests_raw:
207
+ req_data = (
208
+ r
209
+ if isinstance(r, dict)
210
+ else (r.__dict__ if hasattr(r, "__dict__") else {})
211
+ )
212
+
213
+ info = RequestInfo(
214
+ request_id=str(req_data.get("request_id", "")),
215
+ created=str(req_data.get("created", "")),
216
+ path=str(req_data.get("path", req_data.get("endpoint", ""))),
217
+ method=req_data.get("method", ""),
218
+ status="succeeded"
219
+ if req_data.get("response", {}).get("code", 0) < 400
220
+ else "failed",
221
+ duration=float(req_data.get("duration", 0)),
222
+ )
223
+ req_models.append(info)
224
+
225
+ status_style = "green" if info.status == "succeeded" else "red"
226
+ table.add_row(
227
+ info.created[:19] if info.created else "-",
228
+ info.path or "-",
229
+ info.method or "-",
230
+ f"[{status_style}]{info.status}[/{status_style}]",
231
+ f"{info.duration:.2f}s" if info.duration else "-",
232
+ info.request_id[:12] + "..."
233
+ if len(info.request_id) > 12
234
+ else info.request_id,
235
+ )
236
+
237
+ console.print(table)
238
+ console.print(f"\n[dim]{len(req_models)} request(s) shown[/dim]")
239
+
240
+ return RequestsResult(
241
+ status="success", requests=req_models, count=len(req_models)
242
+ )
243
+
244
+ def _show_request(
245
+ self,
246
+ client: DeepgramClient,
247
+ request_id: str,
248
+ project_id: str | None,
249
+ ) -> BaseResult:
250
+ console.print(f"[blue]Fetching request details:[/blue] {request_id}")
251
+ result = client.get_request(request_id, project_id=project_id)
252
+
253
+ console.print("[green]Request Details:[/green]")
254
+ for key, value in result.items():
255
+ if isinstance(value, dict):
256
+ console.print(f" {key}:")
257
+ for k, v in value.items():
258
+ console.print(f" {k}: {v}")
259
+ else:
260
+ console.print(f" {key}: {value}")
261
+
262
+ return BaseResult(status="success", message="Request details displayed")
@@ -0,0 +1,20 @@
1
+ """Models for requests command."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from deepctl_core import BaseResult
6
+ from pydantic import BaseModel, Field
7
+
8
+
9
+ class RequestInfo(BaseModel):
10
+ request_id: str = ""
11
+ created: str = ""
12
+ path: str = ""
13
+ method: str = ""
14
+ status: str = ""
15
+ duration: float = 0.0
16
+
17
+
18
+ class RequestsResult(BaseResult):
19
+ requests: list[RequestInfo] = Field(default_factory=list)
20
+ count: int = 0
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: deepctl-cmd-requests
3
+ Version: 0.0.2
4
+ Summary: Requests history command for deepctl
5
+ Author-email: Deepgram <devrel@deepgram.com>
6
+ Maintainer-email: Deepgram <devrel@deepgram.com>
7
+ License-Expression: MIT
8
+ Keywords: deepgram,cli,requests,history
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ Requires-Dist: deepctl-core>=0.1.10
18
+ Requires-Dist: click>=8.0.0
19
+ Requires-Dist: rich>=13.0.0
20
+ Requires-Dist: pydantic>=2.0.0
21
+
22
+ # deepctl-cmd-requests
23
+
24
+ > Part of [deepctl](https://github.com/deepgram/cli) — Official Deepgram CLI
25
+
26
+ Requests history command for deepctl
27
+
28
+ ## Installation
29
+
30
+ This package is included with deepctl and does not need to be installed separately.
31
+
32
+ ### Install deepctl
33
+
34
+ ```bash
35
+ # Install with pip
36
+ pip install deepctl
37
+
38
+ # Or install with uv
39
+ uv tool install deepctl
40
+
41
+ # Or install with pipx
42
+ pipx install deepctl
43
+
44
+ # Or run without installing
45
+ uvx deepctl --help
46
+ pipx run deepctl --help
47
+ ```
48
+
49
+ ## Commands
50
+
51
+ | Command | Entry Point |
52
+ |---------|-------------|
53
+ | `deepctl requests` | `deepctl_cmd_requests.command:RequestsCommand` |
54
+
55
+ ## Dependencies
56
+
57
+ - `click>=8.0.0`
58
+ - `rich>=13.0.0`
59
+ - `pydantic>=2.0.0`
60
+
61
+ ## License
62
+
63
+ MIT — see [LICENSE](../../LICENSE)
@@ -0,0 +1,11 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/deepctl_cmd_requests/__init__.py
4
+ src/deepctl_cmd_requests/command.py
5
+ src/deepctl_cmd_requests/models.py
6
+ src/deepctl_cmd_requests.egg-info/PKG-INFO
7
+ src/deepctl_cmd_requests.egg-info/SOURCES.txt
8
+ src/deepctl_cmd_requests.egg-info/dependency_links.txt
9
+ src/deepctl_cmd_requests.egg-info/entry_points.txt
10
+ src/deepctl_cmd_requests.egg-info/requires.txt
11
+ src/deepctl_cmd_requests.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [deepctl.commands]
2
+ requests = deepctl_cmd_requests.command:RequestsCommand
@@ -0,0 +1,4 @@
1
+ deepctl-core>=0.1.10
2
+ click>=8.0.0
3
+ rich>=13.0.0
4
+ pydantic>=2.0.0