PrefectHQ
prefect
BlogDocsChangelog

Add `prefect api` command for direct API access

#19131
Comparing
19130-api-command
(
1b338e0
) with
main
(
18000dd
)
CodSpeed Performance Gauge
0%
Untouched
2
Ignored
6

Benchmarks

Passed

bench_task_decorator
benches/bench_tasks.py
CodSpeed Performance Gauge
0%
460.5 µs459.5 µs
bench_import_prefect_flow
benches/bench_import.py
CodSpeed Performance Gauge
0%
1.4 s1.4 s

Ignored

bench_flow_decorator
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-16%
3.4 ms4.1 ms
bench_flow_call[options1]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
+1%
106 ms104.9 ms
bench_task_submit
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
-6%
4.4 ms4.6 ms
bench_import_prefect
benches/bench_import.py
Ignored
CodSpeed Performance Gauge
0%
2.6 ms2.6 ms
bench_flow_call[options0]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-2%
159.3 ms162.3 ms
bench_task_call
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
+4%
170.7 ms164.8 ms

Commits

Click on a commit to change the comparison range
Base
main
18000dd
+0.43%
Add `prefect api` command for direct API access This adds a new `prefect api` command that works like `gh api` for GitHub - a generic HTTP client for the Prefect API that handles auth and URL construction automatically. Key features: - HTTP method as positional argument (e.g., `prefect api POST /flows/filter`) - Smart path handling for Cloud (workspace/account prefixes) and OSS (`/api` prefix) - Multiple input methods: `--data` flag, `@filename`, or auto-detected stdin - Custom headers with `-H` flag (curl/gh compatible) - Alternative `-X` flag for method specification - Pretty-printed JSON output (compact when piped) - Verbose mode with `--verbose` shows request/response headers - Meaningful exit codes: 0=success, 3=auth, 4=client error, 5=server error, 7=network - Default empty body `{}` for POST/PUT/PATCH to support filter endpoints - Uses PrefectClient internally for ephemeral server support and connection pooling URL building uses proper `urllib.parse` for robustness and settings are accessed via `get_current_settings()` following Prefect conventions. Closes #19130 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
0b7ac3e
18 hours ago
by chrisguidry
-0.23%
Update src/prefect/cli/api.py Co-authored-by: Alex Streed <desertaxle@users.noreply.github.com>
fddd7a4
18 hours ago
by chrisguidry
-0.02%
Address PR feedback from Alex and Nate Simplified the interface and improved the implementation based on reviewer feedback: - Removed `-X` flag complexity - HTTP method is now only a positional argument - Using `client.request()` for PrefectClient (returns Response objects) - Added `CloudClient.raw_request()` to match PrefectClient's signature for --root/--account - Validate --root/--account flags are Cloud-only - Removed "HTTP/1.1" from verbose output (just show status code) - Use `typing.Annotated` instead of `typing_extensions.Annotated` - Complete type hints for all dicts: `dict[str, str]`, `dict[str, Any]` - Wrapped examples in triple backticks - Rich output formatting with syntax highlighting for JSON - Refactored all 25 tests to use respx (cleaner, no manual mocking) - Added UUID fixtures for account_id/workspace_id All tests passing with proper respx mocking and CSRF disabled in test settings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
b7f4871
17 hours ago
by chrisguidry
+0.23%
Add future annotations to cloud.py for Python 3.9 Added `from __future__ import annotations` to cloud.py to fix import error in Python 3.9. The `raw_request` method signature uses `dict[str, Any] | None` which requires this import for 3.9 compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
a3d8f74
16 hours ago
by chrisguidry
-0.3%
Rename test_api.py to test_api_command.py Fixes naming conflict with existing tests/_internal/concurrency/test_api.py that was causing pytest import errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1b338e0
16 hours ago
by chrisguidry
© 2025 CodSpeed Technology
Home Terms Privacy Docs