Skip to content

feat: add usage and web2app resources (#parity)#5

Merged
pbertsch merged 1 commit into
mainfrom
feat/usage-web2app-resources
Jun 27, 2026
Merged

feat: add usage and web2app resources (#parity)#5
pbertsch merged 1 commit into
mainfrom
feat/usage-web2app-resources

Conversation

@pbertsch

Copy link
Copy Markdown
Member

Summary

Adds two new resources to the Python SDK to reach parity with the AWSYS.CO MCP server. Both backend endpoints are API-key reachable, and both are implemented in the SDK's dual sync + async structure.

  • usageclient.usage.get()GET /api/user/statsUsageStats. Live account consumption (links, clicks, QR codes, API calls, tracked clicks) plus current tier limits and active overage state. Distinct from me.get(), which returns the static profile.
  • web2appclient.web2app.consume_session(token)GET /api/v1/web2app/{token}Web2AppSession. Single-use deep-link sessions with a 24h TTL; 400/404 are handled by the existing transport error mapping.

New models (Pydantic v2, camelCase aliases)

UsageStats, UsageLimits, UsageOverage, Web2AppSession — all exported from the package surface.

Flexible limit fields: The /api/user/stats handler serializes unlimited caps (-1) as the literal string "unlimited" while finite caps stay integers. Verified against the live backend handler (functions/app/routes/user.js). Those fields (links_per_month, monthly_links, daily_links, monthly_tracked_clicks, qr_codes, folders) are typed Optional[Union[int, str]] to match the actual contract; api_calls_per_month and custom_slugs are always integers.

Other

  • Wired into both Client and AsyncClient, mirroring existing resource attachment.
  • README: added Usage + Web2App sections and Models-table rows.
  • Version bumped 1.1.0 → 1.2.0 (also corrected __version__, which was stale at 1.0.0).

Test plan

  • pip install -e ".[dev]" then pytest153 passed, 26 skipped (skips are credential-gated integration tests, unchanged).
  • New unit tests for both resources, sync + async (MagicMock + AsyncMock, mirroring test_trust_score.py): assert endpoint path, parsed model fields, and an "unlimited" limit value.
  • AsyncClient wiring tests extended for usage + web2app.
  • No ruff/black config present in repo — no lint step to run.

🤖 Generated with Claude Code

Add two new resources to reach parity with the MCP server, both sync and
async:

- usage.get() -> GET /api/user/stats -> UsageStats (live consumption +
  tier limits + overage; distinct from me.get() static profile)
- web2app.consume_session(token) -> GET /api/v1/web2app/{token} ->
  Web2AppSession (single-use, 24h TTL)

New Pydantic v2 models (camelCase aliases): UsageStats, UsageLimits,
UsageOverage, Web2AppSession. Limit fields that the API returns as either
an int cap or the literal "unlimited" are typed Optional[Union[int, str]].

Wired into Client and AsyncClient, exported from package surface. Tests
cover sync + async for both resources, including an "unlimited" limit
value and endpoint-path assertions. Version bumped 1.1.0 -> 1.2.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pbertsch pbertsch merged commit af49c45 into main Jun 27, 2026
1 of 3 checks passed
@pbertsch pbertsch deleted the feat/usage-web2app-resources branch June 27, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant