Commits
Click on a commit to change the comparison rangeAdd `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>18 hours ago
by chrisguidry Update src/prefect/cli/api.py
Co-authored-by: Alex Streed <desertaxle@users.noreply.github.com>18 hours ago
by chrisguidry 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>17 hours ago
by chrisguidry 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>16 hours ago
by chrisguidry 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>16 hours ago
by chrisguidry