Metadata-Version: 2.5
Name: mpt-curl
Version: 1.0.8
Summary: curl-like CLI for the MPT API with automatic collection paging
Requires-Python: <4,>=3.12
Requires-Dist: mpt-api-client>=6.3.1
Requires-Dist: mpt-cli>=5.3.0
Requires-Dist: pygments>=2.19
Description-Content-Type: text/markdown

# mpt-curl

Python replacement for `~/bin/mpt-curl` built on [mpt-api-python-client](https://github.com/softwareone-platform/mpt-api-python-client).

For GET requests to collection endpoints, pages are fetched automatically and streamed to stdout as a single JSON object (`{"data":[...], "$meta":{...}}`).

The first request is sent as-is. Auto-paging starts only if the response has `$meta.pagination`; further pages use `limit=1000` by default. With `total` in pagination, paging follows it; otherwise it continues while each page is full. Disabled when the URL contains `limit=` or `offset=`.

## Install

```bash
pip install mpt-curl
```

## Configuration

Uses the active account from `mpt-cli` accounts (`~/.swocli/accounts.json`, `is_active: true`), same as the shell wrapper.

Override with environment variables:

- `MPT_API_BASE_URL`
- `MPT_API_TOKEN`

## Usage

```bash
# List agreements (auto-paged)
mpt-curl /commerce/agreements

# Same with /public/v1 or /v1 prefix — resolved like the shell script
mpt-curl /public/v1/commerce/agreements
mpt-curl /v1/commerce/agreements
mpt-curl /commerce/agreements

# Filter with RQL
mpt-curl '/commerce/agreements?and(eq(status,Active))'

# Single page (limit= or offset= in URL disables auto-paging)
mpt-curl '/commerce/agreements?limit=10'

# POST (-d alone implies POST, like curl)
mpt-curl /commerce/orders -d '{"type":"Change","agreement":{"id":"AGR-123"}}'
mpt-curl -X POST /commerce/orders -d '{"type":"Change","agreement":{"id":"AGR-123"}}'

# PUT with body
mpt-curl -X PUT /commerce/orders/ORD-123 -d '{"status":"Processing"}'
```

## Options

| Flag | Description |
|------|-------------|
| `-X METHOD` | HTTP method (default: GET, or POST when `-d` is given) |
| `-d DATA` | Request body (JSON) |
| `-H NAME:VALUE` | Extra header |
| `--no-page` | Disable automatic paging |
| `--page-size N` | Page size for auto-paging (default: 1000) |
| `--compact` | Compact JSON output |
| `-v` | Log requests, status, and paging to stderr (gray when stderr is a TTY) |
| `-vv` | Also include response headers |

Automatic paging is also disabled when the URL already contains `limit=` or `offset=`.

## Development

From a checkout:

```bash
uv sync --group dev
uv run pytest
```

